我有一个对象数组
self.components = [{componentId:'', name:'', value:''}];
$scope.components = [{componentId:'', name:'', value:''}];
每个组件都动态推送到数组,如下所示
for(var i=0; i<d.length; i++){
$scope.licenseComponents.push(d[i]);
self.licenseComponents.push(d[i]);
$scope.components.push({componentId:d[i].licenseComponentDefId, name:d[i].name, value:''});
self.components.push({componentId:d[i].licenseComponentDefId, name:d[i].name, value:''});
}
构建此数组后,每个数组对象的components [i] .value将动态设置为ng-model,如下所示,生成的HTML如下所示。
var ip = document.createElement("input"); //input element, text
var label = document.createElement("label");
ip.setAttribute('type',"text");
var id = "id";
id = id.concat(self.licenseComponents[i].licenseComponentDefId);
ip.setAttribute('id', id );
var ngModel = "components[";
ngModel = ngModel.concat(i);
ngModel = ngModel.concat("].value");
ip.setAttribute('ng-model',ngModel);
form.appendChild(ip);
form.appendChild(label);
var myNode = document.getElementsByTagName('div').namedItem("dynamicElements");
myNode.appendChild(form);
但是当输入文本元素的值时,$ scope.components.value不会更新。有人能指出这里出了什么问题吗? TIA