2015-12-15 44 views
0

通過輸入表單上的選擇框選擇與其父母的belongsTo關聯有困難。問題Ember選擇框選擇一種形式的子關聯

型號

export default DS.Model.extend({ 
    proNumber: DS.attr('number'), 
    status: DS.attr('string'), 
    special: DS.attr('string'), 
    customer: DS.belongsTo('customer', { async: true }), 
    carrier: DS.belongsTo('carrier', { async: true }), 
    equipmentList: DS.belongsTo('equipment-list', { async: true}), 
    stops: DS.hasMany('stop'), 
    loadRates: DS.hasMany('load-rate'), 
    grossPay: Ember.computed.mapBy('loadRates', 'rate'), 
    totalGrossPay: Ember.computed.sum('grossPay') 
}); 

模式,我想聯想是客戶之上。

輸入 - 從材料 - 工程完全像大多數選擇框灰燼插件

{{md-select content=customerList 
    value=model.customer <-- doesn't work 
    label="Customer" 
    prompt="Please Choose a Customer..." 
    optionLabelPath='content.name' 
    optionValuePath='content.id'}} 

值不起作用。

+0

你的ID進行比較?也許它是'value = model.customer.id'? – GSP

+0

@GSP這給了我'未捕獲的錯誤:斷言失敗:記錄的ID一旦處於加載狀態就不能改變' –

回答

-1

belongsTo意味着它是一個單一的對象。不是像對象那樣的數組。

爲什麼要爲單個對象使用選擇框?

+0

其他的方法。客戶有很多負載。在負載上,我選擇了一個客戶。 –

0

我猜想,您可能需要改變

optionValuePath='content.id' 

optionValuePath='content' 

或沒有行的。那麼也許該組件支持屬性「選擇」而不是「值」,儘可能多的選擇組件。

我也曾有過類似的問題對不同的選擇成分,我想在此補充,因爲我知道,試圖解決我的問題,當我無意中發現了這個線索有一點不同的情況。我如何解決它是通過以下。我有一個「問題」,有很多答案,其中一個可以被選作「正確答案」。

answers: DS.hasMany('answer'), 
correctAnswer: DS.belongsTo('answer'), 

correctAnswerId: Ember.computed('correctAnswer', 'correctAnswer.id', { 
    get() { 
     return this.get('correctAnswer.id'); 
    }, 
    set(key, value) { 
     this.set('correctAnswer', this.get('answers').findBy('id', value)); 
     return value; 
    } 
}),