简体   繁体   English

AngularJS 中 ngRepeat 中的 ngRepeat 问题

[英]Problem with ngRepeat inside ngRepeat in AngularJS

I am having an issue with ngRepeat that I just can't seem to solve.我遇到了一个似乎无法解决的 ngRepeat 问题。 You can see the issue here: https://codepen.io/markbernard/pen/ExWvJLe .您可以在这里看到问题: https://codepen.io/markbernard/pen/ExWvJLe

The relevant area looks like this code starting on line 59:相关区域看起来像从第 59 行开始的代码:

<div style="border:2px dashed #8f8" ng-repeat="(indexl1, sectionLevel1NavigationItem) in leftNavSectionItem.sectionLevel1Navigation">
    <h4><span data-i18n="common.sectionl1navigation">Section Level 1 Navigation</span> - {{indexl1 + 1}}</h4>
    <div>Acronym level 1 = {{sectionLevel1NavigationItem.acronymOnly}}</div>
    <div> <!-- acronym -->
        <fieldset>
            <legend data-i18n="common.displayAcronym">Display Only Acronym</legend>
            <label><input type="radio" name="acronymOnly{{index}}{{indexl1}}" value="y" ng-model="sectionLevel1NavigationItem.acronymOnly" /><span data-i18n="common.yes">Yes</span></label>
            <label><input type="radio" name="acronymOnly{{index}}{{indexl1}}" value="n" ng-model="sectionLevel1NavigationItem.acronymOnly" /><span data-i18n="common.no">No</span></label>
        </fieldset>
    </div>
    .
    .
    .
</div>

There are 3 levels: Section Navigation, Section Level 1 Navigation and Section Level 2 Navigation.有 3 个级别:部分导航、部分 1 级导航和部分 2 级导航。 Level 2 only appears inside level 1 and level 1 only appears inside the Section Navigation.级别 2 仅显示在级别 1 内,级别 1 仅显示在部分导航内。 The issue only appears in the Level 1 Navigation on the acronym radio button.该问题仅出现在首字母缩写词单选按钮上的 1 级导航中。 It does not properly set up the bind.它没有正确设置绑定。 Neither Yes nor No are selected, even though there is a value in the bound variable.即使绑定变量中有值,也不会选择是或否。 You can see it visually.你可以直观地看到它。 I added some plain text showing the value right above it.我添加了一些纯文本,显示其正上方的值。 Also if you click the Yes or No radio button you can see the value change in the text portion, so it is properly bound.此外,如果您单击“是”或“否”单选按钮,您可以看到文本部分中的值发生变化,因此它已正确绑定。 It is doubly weird since the other bound values in the same level work fine.这是双重奇怪的,因为同一级别中的其他绑定值工作正常。

I even tried a hack to find all the acronym elements, after render, and set them based on the appropriate bound value.我什至尝试在渲染后找到所有首字母缩略词元素,并根据适当的绑定值设置它们。 That didn't work either.那也没有用。

I have rewritten it twice to try to see if I am making a mistake.我已经重写了两次,看看我是否犯了错误。 Searching turns up nothing.搜索一无所获。

Can anyone see if I am missing something?谁能看看我是否遗漏了什么? Or is this some obscure bug?或者这是一些不为人知的错误?

The best spot to see it is " Section Navigation - 2 ".看到它的最佳位置是“ Section Navigation - 2 ”。 The first level 1 has a level 2 below it.第一个级别 1 在其下方有一个级别 2。 The level 1 acronym does not work but the level 2 does.级别 1 的首字母缩写词不起作用,但级别 2 可以。

Unfortunately I could not find a clean solution.不幸的是,我找不到干净的解决方案。 The only thing I could do was to find all the acronymOnly radio buttons, after render, and set the appropriate one to checked in Javascript.我唯一能做的就是在渲染后找到所有的 acronymOnly 单选按钮,并在 Javascript 中设置适当的单选按钮。 The first time I tried to do this I must have made a mistake.我第一次尝试这样做时,我一定犯了一个错误。 The last time I tried I got it to work.我最后一次尝试让它工作。

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

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