【问题标题】:Retrieve data from input on nested array从嵌套数组的输入中检索数据
【发布时间】:2023-03-12 03:39:01
【问题描述】:

我有一个嵌套数组,我从服务器获取数据,我想将新数据从 SELECT 框放入服务器。我的对象数据绑定正确,但嵌套部分没有。无论我在选择输入中输入什么,它都会坚持原始数据。

HTML:

<div class="AL_box" ng-repeat="alarm in alarms">


<li>Alarm {{$index}} </li> <li>
<li>
    <button type="button" class="ok_button" ng-click="alarmsClk(alarm, $index)">Ok</button>
</li>
<br>
<h2>Setpoint: </h2><br>
<div class="sp_box" ng-repeat="setpoint in alarm.setpoints track by $index">
    <li>#{{$index}}<input class="setpoint" type="number" name="#ch" min="5" max="35" step="0.5" ng-model="setpoint"></li>
</div>

JS

$scope.alarmsClk = function($scope, index) {
    var chanObj = { index : index, data : $scope };
    console.log(chanObj)
    service.putAlarms(chanObj, function() {});
}

返回 JSON

data: {switch: "Off", type: "tuesday", hour: 3, minute: 0,…}
hour: 3
minute: 0
setpoints: [21, 21, 21, 21, 21, 21, 21, 21, 21, 21]
switch: "Off"
type: "tuesday"
index: 0

设定点从不绑定。

【问题讨论】:

    标签: angularjs nested angularjs-ng-repeat


    【解决方案1】:

    试试这个

    <input class="setpoint" type="number" name="#ch" min="5" max="35" step="0.5" ng-model="alarm.setpoints[$index]">
    

    JSFiddle

    【讨论】:

      猜你喜欢
      • 2018-12-15
      • 2017-08-28
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 2020-03-03
      • 2021-06-25
      • 2021-08-07
      • 2017-06-09
      相关资源
      最近更新 更多