3
AppController = Ember.ArrayController.extend
cat_id: ''
subcat_data: (->
  App.Subcategory.find({ parent_id: @get("cat_id") })
).property('cat_id').cacheable()

categorySub: (->
 result = Ember.A()
 for category in this.toArray()
    @set('cat_id', category.id)
    @sub = @get("subcat_data")
    console.log @sub
    result.pushObject({
      category: category
      subcategories: @sub.toArray()
    })

result.toArray()
).property('@subcat_data', '@each')

console.log @sub にゼロ オブジェクトのコンテンツを表示するようになりました

DS.AdapterPopulatedRecordArray:ember768> {クエリ={...}、コンテンツ=[0]、ストア=、その他...}

しかし、firebug DOM をチェックインすると、オブジェクトの内容が表示されます [17, 18]

ここで何が間違っていますか?

4

1 に答える 1

0

を使用している場合Ember-data、 のコンテンツはControllerArrayすぐには入力されません。console.log を介して内容を要求すると、Ember-data はPromise空のオブジェクトである を返します。このオブジェクトRecordArrayの内容は、将来のある時点で入力されます。 . DOM でコンテンツを確認するときには、コンテンツはすでに埋められています。これを検証するより良い方法は、コンテンツがいっぱいになったときにのみ console.log を呼び出すことです。

contentDidChange: function() {
  console.info(this.get('content'));
}.observes('content.isLoaded')
于 2013-01-15T18:27:26.517 に答える