1. 判断某个元素是否在数组中。

    setCheckNodes : function (zNodes, checkIds){
var that = this;
that.setAllNodesUnchecked(zNodes);
$.each(checkIds, function(codeIndex, code){
$.each(zNodes, function (nodeIndex, node) {
if(node.code==code){ //for很慢
node.checked = true;
}
if(node.children){
that.setCheckNodes(node.children, checkIds);
}
}); }); return zNodes;
},

indexOf 很快

    setCheckNodes : function (zNodes, checkIds){
var that = this;
that.setAllNodesUnchecked(zNodes);
$.each(zNodes, function (nodeIndex, node) {
if(checkIds.indexOf(node.code) !== -1){
node.checked = true;
}
if(node.children){
that.setCheckNodes(node.children, checkIds);
}
});
return zNodes;
},
04-30 05:17