灰烬路线未显示模板内容 [英] Ember route not displaying template content

查看:63
本文介绍了灰烬路线未显示模板内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Ember和JS的新手,到目前为止,我发现的最广泛的教程是使用1.0.0 pre2,但是在官方站点上有一个非常漂亮的描述以及1.0.0 pre4的一些示例。我开始使用它。我被困在路由中,这是我的代码:

I am new to Ember and JS, so far the most extensive tutorials I found were using 1.0.0 pre2, but on the official site there is a very nice description and some examples of 1.0.0 pre4. I started to use that. I am stuck at routing, here is my code:

index.html

index.html

<body>
        Loaded.
        <script type="text/x-handlebars" data-template-name="application">
            In template displaying val: {{name}}

            {{#linkTo "index"}}<img class="logo">{{/linkTo}}

            <nav>
              {{#linkTo "about"}}About{{/linkTo}}
              {{#linkTo "favorites"}}Favorites{{/linkTo}}
            </nav>

        </script>

        <script type="text/x-handlebars" data-template-name="about">
            Here comes the about text: {{str}}
        </script>
</body>

app.js

window.App = Ember.Application.create();

App.ApplicationView = Ember.View.extend({
templateName: 'application'
})

App.ApplicationController = Ember.Controller.extend({
name: 'test'
})

App.AboutView = Ember.View.extend({
templateName: 'about'
})

App.AboutController = Ember.Controller.extend({
str: 'my string'
})


App.Router.map(function() {
 this.route("about", { path: "/about" });
 this.route("favorites", { path: "/favs" });
});

它几乎与网站上的相同。我想要并认为应该发生的事情是,它将显示about模板的内容,而只是将网址更新为/#/ about或/#/ favs。我在这里想念什么?

It's almost identical to the one from the site. What I want and think should happen, is that it will display the content of about template, but instead it just updates the url's to /#/about or /#/favs . What am I missing here?

推荐答案


我想要并认为应该发生的事情是,它将显示about模板的内容,但只是将网址更新为/#/ about或/#/ favs。我在这里错过了什么?

What I want and think should happen, is that it will display the content of about template, but instead it just updates the url's to /#/about or /#/favs . What am I missing here?

您的应用程序模板没有 {{outlet}}

Your application template does not have an {{outlet}}. With that in place it will work as expected.

请参阅此 jsbin 作为工作示例。

See this jsbin for a working example.

这篇关于灰烬路线未显示模板内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆