我有一個狀態標誌從服務器返回的數據。並在每個ItemView控件我有一些單選按鈕,如下所示:Marionette ItemView和單選按鈕
<td><input type='radio' name='<%- id %>-typeRecipe' value='0'></td>
<td><input type='radio' name='<%- id %>-typeRecipe' value='2'></td>
<td><input type='radio' name='<%- id %>-typeRecipe' value='1'></td>
由於正在創建的每個ItemView控件我要檢查,如果服務器返回的狀態是相同的值作爲輸入值,即無論是0,1,或2,如果它設置該元素選擇。
Recipe = Marionette.ItemView.extend({
ui: {
comm: 'input[type=radio]'
},
onBeforeRender: function() {
for (var i = 0; i < this.ui.comm.length; i++) {
if(parseInt(this.ui.comm[i].value, 10) === this.model.get('status')) {
this.ui.comm[i].$el.prop('selected')
}
}
}
但是,當我查看接口時,沒有一個單選按鈕檢查它們。
當我調試代碼時,我可以看到行0123¾正在執行,所以我想知道爲什麼它不顯示將元素設置爲選中?順便說一句我嘗試在onRender事件上使用該功能,但也有相同的結果
乾杯 - 我已經開始使用你的方法,但與語法脫鉤。謝謝你讓我再次踏上正確的道路。作品一種享受 –