1
我正在嘗試創建我的第一個Meteor應用程序,並且卡在什麼應該是一個簡單的過程。這裏是我用來首先設置數據庫的插入;
income.insert({income_acct_name: "Account 1", income_acct_budget: 0, income_acct_total: 0});
income.insert({income_acct_name: "Account 2", income_acct_budget: 0, income_acct_total: 0});
income.insert({income_acct_name: "Account 3", income_acct_budget: 0, income_acct_total: 0});
這裏是模板;
<template name="income">
{{#each accounts}}
<tr>
<td class="row1"><input type="text" value="{{income_acct_name}}"></td>
<td class="row2"><input type="text" value="{{income_acct_budget}}"></td>
<td class="row3">0%</td>
<td class="row4"><input type="text" value="0" id="income_amt_entered"></td>
<td class="row5">$ </td>
<td class="row6"> - </td>
<td class="row7"></td>
</tr>
{{/each}}
</template>
並且這是引發錯誤的助手;
Template.income.events ({
'change td.row4': function(theEvent, theTemplate) {
var rowId = this._id;
Session.set('changedRow', rowId);
var changedRow = Session.get('changedRow');
var amount = theTemplate.find('#income_amt_entered').value;
income.update (
{"_id": changedRow},
{$inc: {"income_acct_total": amount}}
)
//console.log(amount);
}
});
所以在我的形式,我在ROW4輸入金額45.50喜歡更新「income_acct_total」,我得到這個錯誤。我使用的是與正在工作的Leader Board應用程序幾乎相同的代碼。輸入的金額在控制檯日誌中正確顯示。
也做到了。我希望將輸入驗證保存到應用程序中,以便在開始時保持簡單。猜猜我不能那樣做。非常感謝! – 2014-09-29 15:20:48
$ inc期望數字不是字符串。這就是原因。 – 2014-09-29 15:26:41