EmberJS嵌套资源模板不起作用

时间:2015-03-05 09:14:33

标签: javascript ember.js

我有一个Ember应用程序,它不会为嵌套资源的路由加载模板。很确定我在这里遗漏了一些非常明显的东西,但我无法弄清问题是什么。

每当我转到http://localhost:4200/dashboard/appointments/new时,我都会得到一个空白页。

这是我的router.js文件:

import Ember from 'ember';
import config from './config/environment';

var Router = Ember.Router.extend({
  location: config.locationType
});

Router.map(function() {
  this.route('signup', { path: '/register' });
  this.route('login', { path: '/login' });
  this.route('logout', { path: '/logout' });

  this.resource('user', { path: '/dashboard' }, function() {
    this.resource('appointment', { path: '/appointments' }, function() {
      this.route('new', { path: '/new' });
    });
    this.resource('item', { path: '/items' }, function() {});
  });
});

export default Router;

这是我的目录结构:

|__app.js
|__controllers
| |__login.js
|__router.js
|__routes
| |__application.js
| |__login.js
| |__logout.js
| |__signup.js
| |__user
| | |__appointment
| | | |__new.js
| | |__appointment.js
| | |__item.js
| |__user.js
|__templates
| |__application.hbs
| |__components
| |__login.hbs
| |__logout.hbs
| |__partials
| |__signup.hbs
| |__user
| | |__appointment
| | | |__new.hbs
| | |__appointment.hbs
| | |__item.hbs
| |__user.hbs

我确保(在我的templates目录中),我的user.hbs文件和我的user/appointment.hbs文件都有{{outlet}}。我检查了控制台,URL工作正常(没有URLNotFound错误)。唯一的问题是templates/user/appointment/new中的模板未加载。现在所有其他模板都是空的,其中包含{{outlet}}

任何想法可能是什么问题?真的很感激帮助!

1 个答案:

答案 0 :(得分:2)

根据您当前的路由结构,您需要新的约会模板位于templates/appointment/new

JSBin

另一种自行调试的方法是使用Ember Inspector插件。转到您要弄清楚的URL,转到检查器的“路径”部分,选中该框以限制您对当前路径的显示,然后查看模板列下要查找的模板。在您的情况下,它表示正在appointment/new寻找模板。