1
我有一个名为域的父节点,我们可以在它下面添加多个子节点,并且在每个子节点下我们可以添加多个子子节点。我想创建一个结构类似这样的有没有什么方法创建一个哈希映射像结构
我想下选择业务域添加subchild。它工作正常进行的第一要素,但是当我在任何其他业务领域增加subchild选择它增加了这样创建的所有subchild:
这是我服务方法我在哪里存储subchild列表:
app.factory('DomainNameService',['$q', function($q) {
var childSubDomainName=[];
setBusSubDomain:function(val,busDomain){//In val I am getting the business
//domain selected and in busDomain I am getting the name entered in name field
if(childSubDomainName.length<1){
childSubDomainName.push(busDomain);
}
else {
for(var i=0;i<childSubDomainName.length;i++){
var index = childSubDomainName[i].name.indexOf(busDomain.name);//Added this for unique name check
}
if(index==-1){//If the name is unique then i allow it to add to childSubDomainName
//Here I want to implement a logic that busDomain gets add only to the parent selected but I am not getting how to do this
childSubDomainName.push(busDomain);
}
else
this.error = 'Name already in use';
}
},
}
我得到这种类型的结构为childSubDomainName
任何人都可以请建议我如何做到这一点。我尝试了很多东西,但没有奏效。
什么是你'for'循环点维持? – Phil
我添加了for循环来检查正在添加的名称是否是唯一的 –
但除了继续重新分配'index'外,没有其他任何操作,因此导致'index'只与最后一个'childSubDomainName'有关 – Phil