如果ember-power-select具有選定的值/東西,我該如何檢查Ember?Ember-Power-Select:檢查是否選擇了事端?
編輯: 我已經有onchange =(動作(mut選擇))。 但我有一個計算屬性,它在'選擇'上進行監聽。 當我第一次訪問該網站(網址或重新加載)時,選擇將根據model.name填充。該值顯示在功率選擇中,但計算出的屬性不會被調用
如果ember-power-select具有選定的值/東西,我該如何檢查Ember?Ember-Power-Select:檢查是否選擇了事端?
編輯: 我已經有onchange =(動作(mut選擇))。 但我有一個計算屬性,它在'選擇'上進行監聽。 當我第一次訪問該網站(網址或重新加載)時,選擇將根據model.name填充。該值顯示在功率選擇中,但計算出的屬性不會被調用
通過優秀的文檔http://www.ember-power-select.com/docs/action-handling。其實它的以下DataDownActionsUp原則,chnages將通過行動來傳達。
您需要定義onchange
行動
{{#power-select
selected=destination
options=cities
onchange=(action "chooseDestination")
as |name|
}}
{{name}}
{{/power-select}}
落實相應位置的邏輯,
import Ember from 'ember';
export default Ember.Controller.extend({
cities: ['Barcelona', 'London', 'New York', 'Porto'],
destination: 'London',
actions: {
chooseDestination(city) {
this.set('destination', city);
// this.calculateRoute();
// this.updatePrice();
}
}
});
如果你想單獨更新selected
財產,那麼你可以簡單地說onchange=(action (mut destination))
是的,我知道,對不起,它需要更多的描述。請看我的編輯 –
'選擇將根據model.name'填充 - 你在哪裏設置這個發生?請包括該代碼 – kumkanillam
嘿,我犯了一個錯誤。計算屬性只能聽'選擇',但我必須聽取'selection.name',因爲它是一個模型 –