角;如何使用itemindex更新有序数组 [英] Angular; How do I update an ordered array using itemindex

查看:107
本文介绍了角;如何使用itemindex更新有序数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一张表,我可以使用ng-repeat行中的orderBy过滤器按列排序。我有一个上下文菜单,可以更新该项目更新行:



 [' 运行Api'功能($ itemScope){
< span class =code-keyword> var item = {};
angular.copy($ itemScope.item,item); // 从重复行中获取项目
item.ApiDiff = spinner; // 将当前图像更改为微调器
angular.copy(item,$ scope。项目[$的itemscope $指数。]); // 将项目复制回数组
// 做一些其他的东西并获得ApiDiff的新价值
}]





(我的函数返回正数的绿色向上箭头,负数的红色向下箭头和spinner一词的spinner.gif。这是一个简单的方法在我们等待更新的结果时将图像设置为微调器。



我遇到的问题是$ itemScope。$ index是订购商品的索引数组,而$ scope.Items是无序数组。随着排序,我得到一个未命中的比赛。



如何更新阵列中的原始项目?



谢谢^ _ ^

Andy

解决方案

itemScope){
var item = {};
angular.copy(


itemScope.item,item); // 从重复行中获取项目
item.ApiDiff = spinner; // 将当前图像更改为微调器
angular.copy(item,

scope.Items

Hi,

I have a table which I can sort by columns by using the orderBy filter in an ng-repeat row. I have a context menu that can make updates to that item up updates the row:

['Run Api', function ($itemScope) {
   var item = {};
   angular.copy($itemScope.item, item); //get the item from the repeat row
   item.ApiDiff = "spinner"; //change the current image to a spinner
   angular.copy(item, $scope.Items[$itemScope.$index]); //copy the item back to the array
   //Do some other stuff and get the new value for ApiDiff
}]



(I have a function that returns a green up arrow for positive numbers, a red down arrow for negative and a spinner.gif for the word "spinner". This is an easy way of setting the image to a spinner while we wait for the updated result)

The issue I have is that $itemScope.$index is the index of the item in the ordered array whereas $scope.Items is the un-ordered array. With sorting on, I get a miss match.

How do I update the original item in the array?

Thanks ^_^
Andy

解决方案

itemScope) { var item = {}; angular.copy(


itemScope.item, item); //get the item from the repeat row item.ApiDiff = "spinner"; //change the current image to a spinner angular.copy(item,


scope.Items


这篇关于角;如何使用itemindex更新有序数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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