加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 07:32:10 所属栏目:安全 来源:网络整理
导读:我在对象上使用嵌套的ng-repeat和过滤器.第一个ng-repeat是对gapHeader对象中headerId的过滤.第二个ng-repeat过滤gapSection,sectionId到相应的headerID. 我有一个编辑页面,它位于一个单独的模态窗口中.目的是编辑对应于headerID的内容.子对象的sectionID)这
我在对象上使用嵌套的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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读