首页 > 代码库 > knockout.js(js)代码在IE中出现“意外地调用了方法或属性”的错误

knockout.js(js)代码在IE中出现“意外地调用了方法或属性”的错误

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var CartListViewModel = function () {
    var self = this;
 
    self.payment = [
                { name: "", value: 1 },
                { name: "", value: 2 },
            ];
 
    self.items = ko.observableArray([]);    // {‘id‘:1,‘data‘:[‘aa‘,‘bb‘]}
 
    self.load = function () {
       
 
         var data = http://www.mamicode.com/;
         
 
        var items = new Array();
        for (var i in data) {
            var dataItem = data[i];
 
            var cartItem = new CartItemViewModel()
            。。。
 
            items.push(cartItem);
        }
        self.items(items);
    };
 
    self.TotalSum = function(){
        var totalsum = 0;
        var ilength = this.items().length;
        for(var idx = 0; idx < ilength; idx++)
        {
            var iItem = this.items()[idx];
            if (iItem.selected())
            {
                totalsum = totalsum + iItem.goodsPrice();
            }
        }   
 
        return totalsum.toFixed(2);           
    }
 
 
}

 上面部分knockout.js代码,其中,TotalSum函数中,return totalsum;(原来的代码)在FF中正常运行,但在IE总出现“意外地调用了方法或属性”的错误。后来在代码后加了toFixed(2)后正常。