Meteor在数字上获取不正确的值类型

时间:2014-11-06 22:08:22

标签: javascript meteor

我有一个表单,用户可以在其中更改记录。提交表单后,我将以前的值与新值进行比较,并记录更改日志集合中所做的任何更改。

我知道在检查金额字段是否已更改之前,需要将金额字段的值转换为数字。我的问题是转换后我的模板助手仍然看到它是一个字符串。

这是代码;

var trxColl = trx.findOne(Session.get('trx_DB_currentID')); // Contains _id of the trx records on the screen
var formColl = theTemplate.findAll('.trx_edit');
formColl.forEach( function(item) {
    docName = "trxColl." + item.name;  // All the input names are the same as the DB field names                
    var value = item.value;
    if (item.name === "trx_amount")
    {
        value = parseFloat(value).toFixed(2);
    }
    if (value !== eval(docName))
    {
        console.log(value+ " has type : " + typeof value + " AND " + typeof eval(docName) + " has type : " + eval(docName));
    }
});

Input field is-
Amount: <input type="text" name="trx_amount" value="{{trx_amount}}" id="trx_amount" class="trx_edit">

这是我在我的控制台中获得的内容;

568.00 has type : string AND 568 has type : number 

当我像这样更新数据库时 -

trx.update({'_id': 'roJ4w9jg6htSF8vfj' }, {$set: {'trx_amount': 568.00}}) 

它总是显示为568.

0 个答案:

没有答案