0
我正在Ember.js 和我有一個select元素設置爲發送值「onchange」我收到的值沒有任何問題.. 但我想保存每一個選擇到一個數組並顯示它在標籤 這裏飛是我template.hbsEmber js pushObject覆蓋陣列
<div class="panel-body">
<div class="form-group">
<select name="services" id="services" class="form-control" onchange={{action 'setValue' value="target.value"}}>
<option> Select Services </option>
{{#each services as |service|}}
<option value="{{service.name}}">{{service.name}}</option>
{{/each}}
</select>
</div>
<div class="form-group">
{{selectedService}}
{{#each selectedService as |selection index|}}
<span class="label label-primary">{{index}} {{selection}}</span>
{{/each}}
</div>
</div>
,這裏是我的控制器
actions: {
setValue(ser){
var selectedService = [];
this.set('selectedService', ser);
selectedService.pushObject(ser);
console.log(selectedService);
}
我試圖登錄「selectedService [1]」和選擇兩個項目,但事實並非如此工作它不斷覆蓋第一項:(
仍然給我一個錯誤「ReferenceError:selectedService沒有定義」這已經2個小時了..我討厭編程:( – Haboosh
我會爲你準備一個旋律,不要放棄! – alptugd
我會很感激你。 。我會等待..非常感謝 – Haboosh