zoukankan      html  css  js  c++  java
  • cocoscreator查找节点的方法 (跟jquery find一样)

    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一样)

  • 相关阅读:
    [ASP.NET AJAX]Function对象及Type类的方法介绍
    经常用到的Banner服务器控件的开发
    [ASP.NET AJAX]类似.NET框架的JavaScript扩展
    [EnterpriseLibrary]SqlConnection.ConnectionString相关关键字
    [设计模式] Singleton Pattern
    [XNA GAME]今天开始我想和XNA Game交朋友
    把SQL数据库部署到远程数据库服务器中
    [CommunityServer]AJAX客户端说明,XMLHttpRequest对象
    [EnterpriseLibrary].NET程序中配置文件(.config)操作
    [今天我当家]糖醋排骨
  • 原文地址:https://www.cnblogs.com/newmiracle/p/11958446.html
Copyright © 2011-2022 走看看