两个嵌套的 ng-repeat 的数据绑定不起作用
Databinding with two nested ng-repeat does not work
不幸的是,当有两个带有文本框的嵌套 ng-repeat 时,两个数据绑定不起作用。带有 prop 的第一个层次结构有效,但传感器中的第二个层次不将值绑定回模型。
受影响的页面可以在http://wotcloudclient.azurewebsites.net/#/Thing/Create下调用
用户:瓦格纳
密码:test
提前致谢
<div class="well" ng-repeat="prop in properties">
<div class="form-group form-inline">
<h4 ng-show="prop.isMainThing">General</h4>
<input type="text" class="form-control" ng-model="prop.name" placeholder="Name" ng-show="!prop.isMainThing" required>
<input type="text" class="form-control" ng-model="prop.description" placeholder="Description" ng-show="!prop.isMainThing">
<button class="btn btn-danger btn-sm" ng-click="removeThing(prop)" ng-show="!prop.isMainThing"><span class="glyphicon glyphicon-trash"></span> </button>
</div>
<div class="form-group form-inline" ng-repeat="sensor in prop.sensors" style="margin-left: 20px">
<input type="text" class="form-control input-sm" ng-model="sensor.name" placeholder="Sensor name" required>
<select class="form-control input-sm" ng-model="sensor.datatype" ng-options="item.id as item.name for item in datatypes">
</select>
<button class="btn btn-danger btn-sm" ng-click="removeSensor(prop, sensor)"><span class="glyphicon glyphicon-trash"></span> </button>
</div>
<div class="form-group">
<button class="btn btn-primary btn-sm" ng-click="addNewSensor(prop)"><span class="glyphicon glyphicon-plus"></span> <span>Add Sensor</span></button>
</div>
</div>
您的传感器阵列似乎是一个阵列阵列,每个传感器都是一个包含一个对象的阵列。如果将传感器更改为对象数组或将代码更改为:
sensor.property -> 传感器[0].属性
<input type="text" class="form-control input-sm" ng-model="sensor[0].name" placeholder="Sensor name" required>
它应该有效,如评论中所写,如果你证明是一个笨蛋,它会更容易帮助你。
不幸的是,当有两个带有文本框的嵌套 ng-repeat 时,两个数据绑定不起作用。带有 prop 的第一个层次结构有效,但传感器中的第二个层次不将值绑定回模型。
受影响的页面可以在http://wotcloudclient.azurewebsites.net/#/Thing/Create下调用 用户:瓦格纳 密码:test
提前致谢
<div class="well" ng-repeat="prop in properties">
<div class="form-group form-inline">
<h4 ng-show="prop.isMainThing">General</h4>
<input type="text" class="form-control" ng-model="prop.name" placeholder="Name" ng-show="!prop.isMainThing" required>
<input type="text" class="form-control" ng-model="prop.description" placeholder="Description" ng-show="!prop.isMainThing">
<button class="btn btn-danger btn-sm" ng-click="removeThing(prop)" ng-show="!prop.isMainThing"><span class="glyphicon glyphicon-trash"></span> </button>
</div>
<div class="form-group form-inline" ng-repeat="sensor in prop.sensors" style="margin-left: 20px">
<input type="text" class="form-control input-sm" ng-model="sensor.name" placeholder="Sensor name" required>
<select class="form-control input-sm" ng-model="sensor.datatype" ng-options="item.id as item.name for item in datatypes">
</select>
<button class="btn btn-danger btn-sm" ng-click="removeSensor(prop, sensor)"><span class="glyphicon glyphicon-trash"></span> </button>
</div>
<div class="form-group">
<button class="btn btn-primary btn-sm" ng-click="addNewSensor(prop)"><span class="glyphicon glyphicon-plus"></span> <span>Add Sensor</span></button>
</div>
</div>
您的传感器阵列似乎是一个阵列阵列,每个传感器都是一个包含一个对象的阵列。如果将传感器更改为对象数组或将代码更改为:
sensor.property -> 传感器[0].属性
<input type="text" class="form-control input-sm" ng-model="sensor[0].name" placeholder="Sensor name" required>
它应该有效,如评论中所写,如果你证明是一个笨蛋,它会更容易帮助你。