-1
我正在共享我編寫的java腳本代碼,但是我無法將此代碼轉換爲Angularjs。我需要Angular的這個項目。在動態Json數組的情況下將JavaScript代碼轉換爲AngularJS
我需要輸出與此相同,任何方式來做到這一點?
var components={
'name':{
'fname':'test',
'lname':'test1'
},
'password':'',
'dim':{
'dim2':{
'dim3':''
}
},
'ary':{
'ar10':{
'ary2':{
'ary3':''
}
},
'ary11':'hello'
}
};
var result=''; var label=[];
var mylogic=function(obj,source){ /*console.log(obj,source);*/
// console.log(typeof components[obj]);
if(typeof source[obj]=='string'){
return obj +' <input placeholder="'+obj+'" type="text" value=""> <br>';
}else{ //console.log(components[obj]);
var subObj=source[obj]; var tempObj=[];
for(item in subObj){
console.log(item,'--',subObj);
tempObj.push(obj+' => ' +mylogic(item,subObj) );
}
return tempObj;
}
}
for(component in components){
result+= mylogic(component,components);
// console.log('Component',components[component]);
}
var res=document.getElementById('result');
res.innerHTML=result;
@ vinod-louis - 這是我需要的要求,但我不知道如何編碼在angularjs中。 –
如果正確答案是「閱讀文檔並學習Angular」,那麼該問題應該被擱置爲「太寬泛」。 – halfer