我試圖將填充視圖的對象插入數組,但引用以某種方式迷路。我有灰燼圖,其中定義eventmanager進行:在Ember事件處理程序中缺少view.context或templateContext
FrontLine.NewProductButton = Em.View.extend({
tagName: 'button',
classNames: ['addtl_product',],
templateName: 'product-button',
eventManager: Ember.Object.create({
click: function(event, view) {
FrontLine.ProductsController.toggleProductToCustomer(event, view);
}
})
})
這種觀點呈現一大堆的呈現與來自使用#each
幫手ProductsController類對象的屬性按鈕。這部分工作很好。當我點擊任何一個按鈕,點擊事件被解僱,做什麼就給什麼,包括成功調用我已經從我的ProductsController指定的處理函數(toggleProductToCustomer
):
FrontLine.ProductsController = Em.ArrayController.create({
content: [],
newProduct: function(productLiteral) {
this.pushObject(productLiteral);
},
toggleProductToCustomer: function(event, view){
FrontLine.CustomersController.currentCustomer.productSetAdditional.pushObject(view.context);
}
});
我想使用該函數將其視圖的屬性填充到數組中。我的應用程序中的另一個地方(簡單的搜索字段),使用pushObject(view.context)
,效果非常好。然而,在這裏,所有被推入陣列的是undefined
。我嘗試使用view.templateContext來代替,但這並不奏效。當我試着從這些功能中的console.log-ING按鈕的view
對象,我得到我所期望的:
<(subclass of FrontLine.NewProductButton):ember623>
但無論view.context
或view.templateContext
回報undefined
。如何訪問我之後的對象,以便將其添加到我的數組中?
如果您使用get()函數而不是直接訪問您的屬性會發生什麼? – 2012-07-30 22:51:36
get()對於Ember來說絕對是必不可少的,但是如何在view.context上使用它,因爲這是我在訪問時遇到的問題? – XML 2012-07-30 22:58:59
view.get('context')不起作用?也許我根本不理解 – 2012-07-30 23:01:23