简体   繁体   English

Angular.js:仅更新(数据绑定)一项ng-repeat

[英]Angular.js: Update (data-bind) only one item of ng-repeat

I have the following html: 我有以下html:

  <li ng-repeat="friend in friends">
        <span ng-repeat="(key, value) in friend.aktuell">
            <input type="text" ng-model="friend.aktuell[key]"> 
        </span>
      <quick-datepicker ng-model="auditDate"></quick-datepicker>
      <button ng-click="audit(auditDate, friend._id)" class="btn btn-info">Audit</button>
  </li>

Now how can I update only the input fields of the friend[index] - so to speak - that has been clicked via the audit button? 现在,我如何才能仅更新通过审核按钮单击的friend[index]的输入字段?

eg 例如

   $scope.audit = function(auditDate, id){
            $scope.friends[1].aktuell = {someData:someValues}; // this works if the index is hard coded
        });
    };

Above works if the index '1' is hard coded into 'friends[1]', but of course I want to no update this in the second input row, but in the one that has been clicked. 如果索引'1'被硬编码为'friends [1]',则上述方法适用,但是我当然不想在第二个输入行中更新它,而是在已单击的行中更新它。

Idea: Can I pass the current clicked "indexifier" to my audit function or alternatively can I alter the input fields where "friend._id = friend._id"? 想法:我可以将当​​前单击的“索引器”传递给我的审核功能,或者可以更改“ friend._id = friend._id”的输入字段吗?

Screenshot: 屏幕截图:

屏幕1

ng-repeat中有$ index变量可用:

ng-click="audit(auditDate, $index)"

Why don't you pass the friend reference instead of passing its index? 为什么不通过friend参考而不是通过索引呢?

<button ng-click="audit(auditDate, friend)" class="btn btn-info">Audit</button>

And on the controller: 并在控制器上:

$scope.audit = function(auditDate, friend){
        friend.aktuell = {someData:someValues};
    });
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM