我在我的視圖中設置了el
爲特定表格,現在我想循環遍歷該表格,逐行並更新第二個和第三個td
元素。
下面是我最近的嘗試(updateCalc
方法是我工作的地方)。第一次使用骨幹,所以任何智慧的話都是值得歡迎的。
var IndexedView = Backbone.View.extend({
initialize: function (args) {
_.bindAll(this, 'updateCalc')
_.bindAll(this, 'updateAllocation');
//Bind modle change event to view event handler
this.model.bind('change:purchasePayment', this.updateAllocation);
this.model.bind('change:slidervalue', this.updateAllocation);
this.model.bind('change:purchasePayment', this.updateCalc);
this.model.bind('change:slidervalue', this.updateCalc);
this.model.bind('change:fixedRate', this.updateCalc);
this.model.bind('change:returnSpx', this.updateCalc);
},
el: $('#IndexedTable'),
//TRYING TO LOOP THROUGH TABLE HERE
updateCalc: function() {
//Illust = Allocation * (1 + spx)^cap hit
//Guar = Allocation * (1 + 0)^cap hit
var spx = this.model.get('returnSpx');
this.$el.find('tbody tr').each(function (key, row) {
console.log(row);
var capHit = 1;//row.find('td.capHit');
var illust = this.$el.find('td#allocation').text() * Math.pow((1 + spx), capHit);
var guar = this.$el.find('td#allocation').text() * Math.pow(1, capHit);
this.children().eq(1).text(value)
this.children().eq(2).text(value)
});
},
updateAllocation: function() {
var value = this.model.get('purchasePayment') * $('#sliderVal').val();
this.$el.find('td#allocation').text(value);
}
});
HTML
<table id="IndexedTable">
<thead>
<tr>
<th>
Indexed
</th>
</tr>
<tr>
<td>
Allocation
</td>
<td id="allocation">
</td>
</tr>
<tr>
<td>
Cap hits:
</td>
<td>
Illust
</td>
<td>
Guar
</td>
</tr>
</thead>
<tbody>
<tr>
<td class="capHit">
0
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="capHit">
1
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="capHit">
2
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
以下是錯誤消息基於哈米爾的評論我得到
$(this.el).find()使用這個.. – 2014-09-12 18:20:43
怎麼樣:''this.el.find( 'TR')'' – 2014-09-12 18:22:46
使用,對於'.each'或內部得到'td'元素? – NealR 2014-09-12 18:24:18