扩展成员应用程序,包括新的路线,现在没有任何渲染
Extended ember app to include new route and now nothing renders
我正在学习成员教程-
http://coding.smashingmagazine.com/2013/11/07/an-in-depth-introduction-to-ember-js/
并对其进行了编辑,以包含新的模型和路线。最初的教程是一个面向用户集合的CRUD应用程序。我现在想扩展应用程序,以处理这些用户可能学习的科目列表。The router.js
文件现在看起来像这样-
App.Router.map(function(){
this.resource('users', function(){
this.resource('user', { path:'/:user_id' }, function(){
this.route('edit');
});
this.route('create');
});
this.resource('subjects', function(){
this.resource('subject', {path: '/:subject_id'}, function(){
this.route('edit');
});
this.route('create');
});
});
(受试者是一条单独的路线,因为我现在希望能够创建单独的路线)
我添加了一个subjects.js
模型,它看起来像这样:
App.Subject = DS.Model.extend({
name : DS.attr(),
});
App.Subject.FIXTURES = [{
id: 1,
name: 'History',
}, {
id: 2,
name: 'Biology',
}];
主题控制器:
App.SubjectsController = Ember.ArrayController.extend({
sortProperties: ['name'],
sortAscending: true // false = descending
});
a主题路线:
App.SubjectsRoute = Ember.Route.extend({
model: function(){
return this.store.find('subject');
}
});
和我的索引中的一个模板,看起来像这样:
<script type = "text/x-handlebars" id = "subjects">
<ul>
{{#each subject in controller}}
<li>{{subject.name}}</li>
{{/each}}
</ul>
</script>
我已经添加了所有的依赖项,并在教程中遵循了与我在其中描述的用户CRUD应用程序中所做的完全相同的步骤,但现在当我转到浏览器时,没有任何渲染。有人知道为什么吗?
在为您描述的教程中,有一个missing
路由可以捕捉错误的路径,并重定向到users
路由,也许您需要包含它来显示一些内容,因为没有index
路由可以显示一些初始页面。
用以下内容更新您的代码:
router.js
App.Router.map(function(){
this.resource('users', function(){
this.resource('user', { path:'/:user_id' }, function(){
this.route('edit');
});
this.route('create');
});
this.resource('subjects', function(){
this.resource('subject', {path: '/:subject_id'}, function(){
this.route('edit');
});
this.route('create');
});
// this is our 404 error route - see MissingRoute just bellow
this.route('missing', { path: '/*path' });
});
// this handles wrong routes - you could use it to redirect to a 404 route or like here to redirect to the index page
App.MissingRoute = Em.Route.extend({
redirect: function(){
this.transitionTo('users.index');
}
});
相关文章:
- 是否有任何开源web应用程序具有良好的QUnit(或JSUnit)测试用例
- 如何在 Rails 应用程序中使用任何 JavaScript 代码
- PhantomJs:Spawn没有打开任何应用程序
- IE窗口失去了对任何XMLHttpRequest启动Angular应用程序的关注
- JQuery在执行速度上是否有任何缺点,这些缺点在大规模的web应用程序中可能会很明显
- 扩展成员应用程序,包括新的路线,现在没有任何渲染
- 在过去24小时内,谷歌应用程序脚本或可视化API的任何变化
- 是否有任何twitter功能用于登录应用程序
- 是否可以提供一个特定的URL,供任何在网络应用程序中为页面添加书签的人使用
- 有没有任何方法可以在单页应用程序中记录url和哈希片段
- 是否有任何Office Apps javascript API可以在客户端应用程序中打开SharePoint Word文
- 如果我动态创建jquery UI对话框,除了在单页应用程序中调用对话框(“关闭”)之外是否有任何清理
- 在谷歌应用程序脚本中处理脚本,任何建议
- 在 React 应用程序中单击除特定 DOM 节点之外的任何内容上的事件
- Phonegap如何检查Android设备是否已经具有任何地图应用程序
- 有关交互式地图应用程序的任何建议
- 从任何客户端访问帆船应用程序
- 如何在应用程序的多个组件中维护一个 js 文件而不会出现任何错误
- 不允许打开除浏览器之外的任何其他应用程序
- 打印任何java应用程序的函数/方法调用序列