function LineCateCollection(name) { this.name = name; this.length = 0; this.add = addLineCate; return this; } function addLineCate(object) { this.length++; this[this.length] = object } function LineCateNode(id,name) { this.id = id; this.name = name; return this; } function extractLineCateChildrenOf(node,arr) { var children = new LineCateCollection(node); var currentIndex = 1; while (currentIndex <= arr.length) { //arr[currentIndex].id.startWith(node) && if (arr[currentIndex].id.substring(0,node.length)==node && arr[currentIndex].id.length==(node.length+3) ) { children.add(arr[currentIndex]) } currentIndex++ } return children; } linecates=new LineCateCollection("C"); linecates.add(new LineCateNode("C003","国际")) linecates.add(new LineCateNode("C002","国内")) linecates.add(new LineCateNode("C001","海南"))