Ember 无法识别子文件夹中的模型数据
Ember doesn't recognize model data in subfolder
以下路由结构对我来说很好。
但是,每当我将 faculty.js 移动到 faculty 文件夹中时,我的模板就会停止识别数据。静态视图元素仍然正确显示,但数据模型被记录为空。我该如何解决?
faculty.js
import Ember from 'ember';
export default Ember.Route.extend({
model(){
return {name:"Janusz", lastname:"Chudzynski", department:"Test"};
}
});
faculty.hbs
{{outlet}}
<h2>Faculty</h2>
{{log model}}
{{faculty-single facultyModel=model}}
路由器
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType,
rootURL: config.rootURL
});
Router.map(function() {
this.route('colleges');
this.route('departments');
this.route('faculty',{path:'/faculty'});
//this.route('faculty');
});
导出默认路由器;
控制台日志
null
文件夹的层次结构应该与路由器的层次结构非常相似。在你的情况下,你有以下内容:
Router.map(function() {
this.route('colleges');
this.route('departments');
this.route('faculty');
});
这意味着它们都直接在application
路由下,是正确的文件结构:
app
routes
colleges.js
departments.js
faculty.js
要使 /app/routes/faculty/faculty.js
正常工作,您需要将 faculty
路由嵌套在 faculty
路由中:
Router.map(function() {
this.route('colleges');
this.route('departments');
this.route('faculty', function() {
this.route('faculty');
});
});
由于名称连接,父路由的全名是faculty
,嵌套路由的全名是faculty.faculty
。
以下路由结构对我来说很好。
但是,每当我将 faculty.js 移动到 faculty 文件夹中时,我的模板就会停止识别数据。静态视图元素仍然正确显示,但数据模型被记录为空。我该如何解决?
faculty.js
import Ember from 'ember';
export default Ember.Route.extend({
model(){
return {name:"Janusz", lastname:"Chudzynski", department:"Test"};
}
});
faculty.hbs
{{outlet}}
<h2>Faculty</h2>
{{log model}}
{{faculty-single facultyModel=model}}
路由器
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType,
rootURL: config.rootURL
});
Router.map(function() {
this.route('colleges');
this.route('departments');
this.route('faculty',{path:'/faculty'});
//this.route('faculty');
});
导出默认路由器;
控制台日志
null
文件夹的层次结构应该与路由器的层次结构非常相似。在你的情况下,你有以下内容:
Router.map(function() {
this.route('colleges');
this.route('departments');
this.route('faculty');
});
这意味着它们都直接在application
路由下,是正确的文件结构:
app
routes
colleges.js
departments.js
faculty.js
要使 /app/routes/faculty/faculty.js
正常工作,您需要将 faculty
路由嵌套在 faculty
路由中:
Router.map(function() {
this.route('colleges');
this.route('departments');
this.route('faculty', function() {
this.route('faculty');
});
});
由于名称连接,父路由的全名是faculty
,嵌套路由的全名是faculty.faculty
。