var each = function(object, callback) {
var type = (function() {
switch (object.constructor) {
case Object:
return 'Object';
break;
case Array:
return 'Array';
break;
case NodeList:
return 'NodeList';
break;
default:
return 'null';
break;
}
})();
// 为数组或类数组时, 返回: index, value
if (type === 'Array' || type === 'NodeList') {
// 由于存在类数组NodeList, 所以不能直接调用every方法
[].every.call(object, function(v, i) {
return callback.call(v, i, v) === false ? false : true;
});
}
// 为对象格式时,返回:key, value
else if (type === 'Object') {
for (var i in object) {
if (callback.call(object[i], i, object[i]) === false) {
break;
}
}
}
} function sousuojiedian(sousuowenzi) {
var jiedianlistss = cc.director.getScene().children;
var sousuonodelist;
each(jiedianlistss, function(key, value) {
if (value['name'] == sousuowenzi) {
sousuonodelist=value;
} else {
if (value['childrenCount'] > 0) {
each(value['children'], function(key, value) {
if (value['name'] == sousuowenzi) {
sousuonodelist=value;
} else {
if (value['childrenCount'] > 0) {
each(value['children'], function(key, value) {
if (value['name'] == sousuowenzi) {
sousuonodelist=value;
} else {
if (value['childrenCount'] > 0) {
each(value['children'], function(key, value) {
if (value['name'] == sousuowenzi) {
sousuonodelist=value;
} else {
if (value['childrenCount'] > 0) {
each(value['children'], function(key, value) {
if (value['name'] == sousuowenzi) {
sousuonodelist=value;
} else {
if (value['childrenCount'] > 0) {
each(value['children'], function(key, value) {
if (value['name'] == sousuowenzi) {
sousuonodelist=value;
} else {
if (value['childrenCount'] > 0) {
each(value['children'], function(key, value) {
if (value['name'] == sousuowenzi) {
sousuonodelist=value;
} else {
alert('找不到该节点');
return false;
}
})
}
}
})
}
}
})
}
}
})
}
}
})
}
}
})
}
}
})
return sousuonodelist;
}
cocoscreator查找节点的方法 (跟jquery find一样)