使用ng-repeat时如何仅更新特定行 [英] How to update only specific rows when using ng-repeat

查看:191
本文介绍了使用ng-repeat时如何仅更新特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于excel的UI,用户可以在其中更改所需行中的数据. 从mongoDB获取数据后,目前我正在使用ng-repeat显示现有数据.此数据是Json Objects的数组,因此ng-repeat可以正常工作. 现在,我要有一个保存按钮,单击该按钮,应保存所有编辑.我的问题是如何维护或知道哪些行已更改?我可以只发送整个数组并在db中更新,但是当行数很大并且仅一行的数据发生更改时,将产生不必要的开销.因此,让我知道如何进行优化.

I have a UI similar to excel, where the user can change the data in which ever row he wants. Currently i am using ng-repeat to display the existing data, after fetching from mongoDB. This data is an array of Json Objects , so ng-repeat works fine. Now i want to have a single save button, clicking which, all the edits should be saved. My question is how to maintain or know which rows have been changed ?? i can just send the whole array and update in the db, but when the number of rows is large and data of just one row has changed there will be an unnecessary overhead. so let me know how this can be optimised.

预先感谢

推荐答案

$scope.rowsChanged = [];

$scope.Changed = function(row) {
  $scope.rowsChanged.push(row);

}

<div ng-repeat="row in rows track by $index">
  <input type="text" ng-change="Changed(row)" ng-model="row.textValue">
</div>

希望有帮助.

这篇关于使用ng-repeat时如何仅更新特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆