AngularJS – 过滤的ng-repeat中对象的原始索引

前端之家收集整理的这篇文章主要介绍了AngularJS – 过滤的ng-repeat中对象的原始索引前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在对象上使用嵌套的ng-repeat和过滤器.第一个ng-repeat是对gapHeader对象中headerId的过滤.第二个ng-repeat过滤gapSection,sectionId到相应的headerID.

我有一个编辑页面,它位于一个单独的模态窗口中.目的是编辑对应于headerID&的内容.子对象的sectionID)这也有一个单独的控件.数据通过服务共享.

我的问题我有一个按钮用于每个gapSection子对象,它打开编辑页面模态,当我将每个部分中当前部分的$index值传递给服务时,我得到的$index仅对应于第二个ng-重复?例如,如果我单击gapSection上的2 ng-repeat内的按钮(headerId:2,sectionId:2),我得到$1的索引.我需要$index为2,它对应于gapSection中的子对象位置.

是否有可能传递真正的$index,它对应于gapSection的原始未过滤对象中定义的$index?感谢对此的任何评论,谢谢!

宾语:

var data ={
gapHeader:[{headerId:1,name:"General Requiremets",isApplicable:true},{headerId:2,name:"Insurance",isApplicable:false}],gapSection:[{headerId:1,sectionId:1,requirement:"A facility is required to have company structure",finding:null,cmeasures:null,cprocedures:null,personResp:null,isAction:null},requirement:"Organisation must have public liablity",sectionId:2,requirement:"Facility must hold workers compensation insurance",isAction:null}]



};
如果你需要真正的索引,你甚至不需要传递$index属性,只需传递对象并从原始列表中获取索引.

$scope.gapSectionFn = function(obj){
    var idx = data.gapSection.indexOf(obj);
}

另外还不清楚你的问题是否真的可能是嵌套的ng-repeat问题,因为根据你的说法,gapSection是内部ng-repeat,你正在调用内部ng-repeat和需要gapSection索引的调用.它应该是可用的,但是DOM过滤器的存在只会重新生成项目及其索引,您也可以通过执行ng-init获取它,即在视图ng-init =“actIndex = $index”上并使用actIndex.

如果您尝试访问父ng-repeat的索引,那么ng-init比$parent更合适.$index.由于ng-init是专门为此设计的,因此在父ng-repeat上你会写ng-init =“”parentIndex = $index“并使用parentIndex.

猜你在找的Angularjs相关文章