Ember.js 如何将单个记录传递给阵列控制器
希望页面是一个没有余烬的静态页面。单击一张卡时,我会在url参数中传递其id,以便Ember应用程序可以使用它:Ember.js 如何将单个记录传递给阵列控制器,ember.js,ember-data,Ember.js,Ember Data,希望页面是一个没有余烬的静态页面。单击一张卡时,我会在url参数中传递其id,以便Ember应用程序可以使用它: http://cards.com/category?category_id=2&selected_card_id=3 申请途径: @controllerFor('creditCards').set 'content', App.CreditCard.find category_id: categoryId 我想获取所选卡并将其传递给SelectedCardsControl
http://cards.com/category?category_id=2&selected_card_id=3
申请途径:
@controllerFor('creditCards').set 'content', App.CreditCard.find category_id: categoryId
我想获取所选卡并将其传递给SelectedCardsController
@controllerFor('creditCards').set 'content', App.CreditCard.find category_id: categoryId
@controllerFor('selectedCards').set 'content', App.CreditCard.find selectedCardId
问题是SelectedCardsController
是一个数组控制器,当我尝试以这种方式填充其内容时,我得到了uncaughttypeerror的错误:Object[Object Object]没有方法“addArrayObserver”
我的问题是:如何将这一条记录传递给阵列控制器?执行此操作的惯用方法是在Ember中使用
需要。您可以直接从CreditCardsController
中查找属性,或声明计算属性,以简化本地查找,而不是设置SelectedCardsController
的内容
App.SelectedCardsController = Ember.Controller.extend({
needs: 'credit_cards',
creditCardsBinding: 'controllers.credit_cards',
selectedCardId: function() {
return this.get('credit_cards.selectedCardId')
}.property('credit_cards')
});
是打字错误还是你为什么有App.CreditCard
和App.CreditCards
?App.CreditCards
是另一种模式吗?是的,对不起,这是一个输入错误。我解决了这个问题-我在SelectedCardsController上使用了一种方法,将所选的卡添加到内容中(我在我的应用程序中使用这种方法)。我想我也可以获取内容并在路由中使用pushObject
方法: