8
濾波的對象(data
)圍繞對象的數組包裝紙正常工作:
var arr = {"data":
[
{"name":"Alan","height":"171","weight":"66"},
{"name":"Ben","height":"182","weight":"90"},
{"name":"Chris","height":"163","weight":"71"}
]
};
var new_arr = $.extend(true, arr);
new_arr.data = $.grep(new_arr.data, function(n, i){
return n.weight > 70;
});
alert(new_arr.data.length); // answer is 2
然而,濾波而不對象包裝不。
var arr = [
{"name":"Alan","height":"171","weight":"66"},
{"name":"Ben","height":"182","weight":"90"},
{"name":"Chris","height":"163","weight":"71"}
];
var new_arr = $.extend(true, arr);
new_arr = $.grep(new_arr, function(n, i){
return n.weight > 70;
});
alert(new_arr.length); // answer is 1 instead of 2
我不確定問題出在哪裏。任何人都可以指出。謝謝!
我剛剛發現了原因太:)我忘了爲什麼我用延長擺在首位。看來我現在不需要它。非常感謝 :) –