私は 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