我刚开始使用 EmberJS 并尝试定义导航结构。
我想要一个也有子页面的页面对象。我将如何在数据结构中关联它们?
这是我到目前为止所拥有的:
App.Page = DS.Model.extend({
title: attr('string', { defaultValue:''}),
url: attr('string', { defaultValue:''}),
defaultPage: attr('boolean', { defaultValue:false}),
parentPage: attr('string', { defaultValue:''}),
children: attr('string', { defaultValue:''}),
position: attr('string', { defaultValue:'left'}),
getChildren:function(){
return App.NavigationController.filterProperty('parentPage',this.get('title'));
}
});
到目前为止,这是我使用它的方式:
this.pushObject(App.Page.createRecord({
title: "Page",
url: "/page"
}));
this.pushObject(App.Page.createRecord({
title: "Child of Page",
url: "/child_of_page",
parentPage: "Page"
}));
任何指针?
编辑示例:
我正在尝试您的建议,但收到以下信息:
pPg = App.Page.createRecord({title:'Page1'});
pPg.get('childen').pushObject(App.Page.createRecord({title:'cPage1', parentPage:pPg}));
// output TypeError: Cannot call method 'pushObject' of undefined
var cPg1 = App.Page.createRecord({title:'cPage1', parentPage:pPg});
var cPg2 = App.Page.createRecord({title:'cPage2', parentPage:pPg});
pPg.get('children').objectAt(0);
// outputs undefined
pPg.get('children').objectAt(1);
// outputs undefined