1

我可以获得“帮助主题”标题​​来呈现,但没有FIXTURES我定义的标题。{{#each model}}遗嘱中没有任何内容。这是我第一次使用 Ember,所以任何东西(实际上是任何东西)都会有所帮助,因为我在浏览器调试器中没有收到任何错误消息。

应用程序.js

App.Router.map(function () {
    this.resource('home', { path: "/Index" });
    this.resource('agents', { path: "/Agents" });
    this.resource('topics',  function() {
        this.resource('topic', {path: '/topic/:topic_id'})
    });  
    this.resource('contacts', { path: "/Contacts" });
});

App.TopicRoute = Ember.Route.extend({
    model: function () {
        return App.Topic.find();
    }
})

App.Topic = DS.Model.extend({
    title: DS.attr('string'),
    info: DS.attr('string')
});

App.Topic.FIXTURES = [{
    id: 1,
    title: "Periscope",
    info: "Periscope is a read-only application pulling information from D3."
}, {
    id: 2,
    title: "Second post",
    info: "ASP.NET MVC 4 is a framework for building scalable, standards-based web applications using well-established design patterns and the power of ASP.NET and the .NET Framework."
}, {
    id: 3,
    title: "Ember.js",
    info: "Ember.js is designed to help developers build ambitiously large web applications that are competitive with native apps."
}];

看法

                    <script type="text/x-handlebars">
                        <div class="navbar">
                            <div class="navbar-inner">                                
                            <ul id="menu">
                                <li>{{#linkTo 'home'}}Home{{/linkTo}}</li>
                                <li>{{#linkTo 'agents'}}Agents{{/linkTo}}</li>
                                <li>{{#linkTo 'topics'}}About{{/linkTo}}</li>
                                <li>{{#linkTo 'contacts'}}Contact{{/linkTo}}</li>
                            </ul>
                            </div>
                        </div>
                        {{outlet}}
                    </script>


<script type="text/x-handlebars" id="topics">
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span3">
                <table class='table'>
                <thead>
                    <tr><th>Help Topics</th></tr>
                </thead>
                {{#each model}}
                <tr><td>
                    {{#linkTo 'topic' this}}{{title}} {{/linkTo}}
                </td></tr>
                {{/each}}
                </table>
            </div>
            <div class="span9">
                {{outlet}}
            </div>
        </div>
    </div>
</script>
<script type="text/x-handlebars" id="topic">
    <h1>{{title}}</h1>

    <div class="intro">
        {{info}}
    </div>
</script>
4

1 回答 1

1

尝试像这样更改您的路线:

App.TopicsRoute = Ember.Route.extend({
  model: function () {
    return App.Topic.find();
});

希望能帮助到你。

于 2013-08-02T21:13:35.337 回答