Meteor Object不支持属性或方法' find'在IE 9中

时间:2015-01-14 23:27:23

标签: meteor

我一直在使用Chrome和Firefox开发Meteor,一切正常。今天我有人尝试使用IE 9,它不会加载任何使用这些方法的数据;

//Meteor Object doesn't support property or method 'find'
// in this.find("#cashIn_amt_entered" + acct._id).value below

Template.cashInTotals.helpers({
total: function() {
    var totals = {'budgetTotal':0, 'enteredTotal':0, 'sumTotals':0, 'percOfIncome':0};

    // Get the totals from Cash In
    var cashCursor = cashIn.find({"userID": Meteor.userId(), "dash": Session.get("currentDashboard")});
    cashCursor.forEach( function(acct) {
        totals.budgetTotal = totals.budgetTotal + acct.cashIn_acct_budget;
        totals.sumTotals= totals.sumTotals + acct.cashIn_acct_total;
        totals.enteredTotal = totals.enteredTotal + parseFloat(this.find("#cashIn_amt_entered" + acct._id).value);
    });
    var achieved = 0;
    if (totals.budgetTotal > 0)
    {
        achieved = Math.round(totals.sumTotals/totals.budgetTotal*100);
    }

    var array = [];
    array[0] = {'budgetTotal':totals.budgetTotal, 'enteredTotal':totals.enteredTotal, 'sumTotals':totals.sumTotals, 'percOfIncome':achieved};
    return array;
}
})

Meteor应该支持IE 8及更高版本。知道为什么它不理解这一种方法吗?我在10个不同的模板助手中使用this.find来获取数据,所以我真的需要它!

1 个答案:

答案 0 :(得分:0)

进入forEach循环时会丢失上下文。因此,要解决此问题,您可以bind或设置临时变量来保存上下文。

Template.cashInTotals.helpers({
total: function() {
    var totals = {'budgetTotal':0, 'enteredTotal':0, 'sumTotals':0, 'percOfIncome':0};

    // Get the totals from Cash In
    var cashCursor = cashIn.find({"userID": Meteor.userId(), "dash": Session.get("currentDashboard")});
    // Store the context of this
    var that = this;
    cashCursor.forEach( function(acct) {
        totals.budgetTotal = totals.budgetTotal + acct.cashIn_acct_budget;
        totals.sumTotals= totals.sumTotals + acct.cashIn_acct_total;
        totals.enteredTotal = totals.enteredTotal + parseFloat(that.find("#cashIn_amt_entered" + acct._id).value);
    });
    var achieved = 0;
    if (totals.budgetTotal > 0)
    {
        achieved = Math.round(totals.sumTotals/totals.budgetTotal*100);
    }

    var array = [];
    array[0] = {'budgetTotal':totals.budgetTotal, 'enteredTotal':totals.enteredTotal, 'sumTotals':totals.sumTotals, 'percOfIncome':achieved};
    return array;
}
})

那应该解决它。