0

テンプレートのレンダリングが完了したときにDOMでいくつかのアクションをトリガーする必要があるため、ビューのdidInsertElementフックからモデルデータにアクセスしようとしています。

次のようなモデルで:

App.MyParent = DS.Model.extend({
    title: DS.attr('string'),
    childs: DS.hasMany('App.MyChild')
});

App.MyChild = DS.Model.extend({
    name: DS.attr('string'),
    parent: DS.belongsTo('App.MyParent')
});

そして次のようなオブジェクト:

App.MyParent.FIXTURES = [
    { id: 0, title: "some title", childs: [0,2,3] }
]

App.MyChild.FIXTURES = [
    { id: 0, name: "some name", parent: 0 },
    { id: 2, name: "other name", parent: 0 },
    { id: 3, name: "diff name", parent: 0 }
]

フック関数内で、次のようにchildsプロパティにアクセスしています。

var childs = this.get("context.content.childs");

次に、適切な数の子を持つ列挙型を取得しますが、子にはすべて未定義のプロパティがあります。

更新App.MyChild.find(someId) を使用して子にアクセスできる唯一の場所はブラウザー コンソールにあるようです。アプリ コードでは、未定義のプロパティを持つオブジェクトのみを取得します。

私は困惑しています!

4

1 に答える 1

1

childs プロパティにアクセスするには、次のようにします。

var childs = this.get("context.content.childs");

また、関連付けのフィクスチャ データでは、_id または _ids を使用しないでください。したがって、代わりにchildsandを使用します。parent

App.MyParent.FIXTURES = [
  { id: 0, title: "some title", childs: [0,2,3] },
];

App.MyChild.FIXTURES = [
  { id: 0, name: "some name", parent: 0 },
  { id: 2, name: "other name", parent: 0 },
  { id: 3, name: "diff name", parent: 0 },
];

http://jsbin.com/ucanam/316/

于 2013-07-06T17:46:42.383 に答える