gpt4 book ai didi

javascript - Ember 嵌套路线和模型不渲染(根本)

转载 作者:行者123 更新时间:2023-11-28 02:04:10 26 4
gpt4 key购买 nike

我可以获取要呈现的“帮助主题”标题​​,但无法获取我定义的任何FIXTURES{{#each model}} 中的任何内容都不会渲染。这是我第一次使用 Ember,所以任何东西(字面意义上的任何东西)都会有帮助,因为我在浏览器调试器中没有收到任何错误消息。

App.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>

最佳答案

尝试像这样改变你的路线:

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

希望有帮助。

关于javascript - Ember 嵌套路线和模型不渲染(根本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18026178/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com