0
我有模型node
:如何使用指令進行模型輸入?
{"id":"593d408cb25f42a812000042","prefix":"array_simple",
"title":"Array_simple","type":"3","value":["A","B","C"],"nodes":[]}
在這種obejct存在具有值作爲陣列字段值:
"value":["A","B","C"]
如何使用指令來顯示在陣列中的每個值輸入和結合這對模型更改後返回?
我試着寫指令:
.directive('inputArray', function ($compile) {
return {
restrict: 'E',
scope: {
data: "="
},
link: {
pre: function (scope, element) {
scope.inputs = [];
if (angular.isArray(scope.data.value)) {
angular.forEach(scope.data.value, function (value) {
scope.inputs.push({"type": scope.data.type, "value": value});
});
} else {
scope.inputs.push({"type": scope.data.type, "value": scope.data.value});
}
}
},
template: `<input ng-repeat="value in inputs track by $index"
ng-model="node.value"
ng-hide="value.type=='2' || value.type=='6'"
type="text" value="$$value.value$$">`,
replace: true
}
})
但更改後不會改變模型回來。