Enumerating observableArray in knockout casting to string?
This question already has an answer here:
So, the issue is that for...in loops you over the keys to properties of an object, rather than values of the object.
So if you have an object like
var x = {
a: "A",
b: "B"
}
for...in will spit out 'a' and 'b' . Since arrays are objects, for...in with an array will give you something very similar: A string for each index into the array. So, with var a= [1, 2, 3] , for...in of a will result in '0', '1', '2' , rather than 1, 2, 3 .
Use a construct like below to do what you want, instead.
var sss = vm.tripData();
for (var i = 0; i < sss.length; i++) {
var sh2 = sss[i];
sh2.isVisible(false);
}
链接地址: http://www.djcxy.com/p/70026.html
