【问题标题】:using ng-repeat-start and ng-repeat-end with 2 different objects将 ng-repeat-start 和 ng-repeat-end 与 2 个不同的对象一起使用
【发布时间】:2017-03-24 18:54:57
【问题描述】:

我正在尝试为 ng-repeat-start 和 ng-repeat-end 使用 2 个不同的对象。

例如:

             <tr ng-repeat-start="file in files">
                <td class="name-col">{{file.name}}<br>
                </td>
                <td class="name-col">{{file.progress}}</td>
              </tr>
              <tr ng-repeat-end="otherFile in otherFiles">
                <td colspan="2">
                  {{otherFile.errors}}
                </td>
              </tr>

现在似乎不起作用,它只假设第一个对象(文件)

【问题讨论】:

    标签: javascript angularjs loops angularjs-ng-repeat


    【解决方案1】:

    也许这样可以:

    <tr ng-repeat-start="file in files">
                <td class="name-col">{{file.name}}<br>
                </td>
                <td class="name-col">{{file.progress}}</td>
              </tr>
              <tr ng-repeat-end>
                <td colspan="2">
                  {{otherFiles[ $index ].errors}}
                </td>
              </tr>
    

    【讨论】:

    • @jeremy 它不起作用?还是不是你想要的方式?
    【解决方案2】:

    您的问题是ng-repeat-end 不接受参数。 如果你想ng-repeat 像上面那样覆盖不同的对象,你需要启动一个新的ng-repeat 块。

    编辑:添加了包装 html 以显示一个点。你可能想稍微改变一下。

       <div ng-repeat="file in files track by $index">
        <tr>
            <td class="name-col">{{file.name}}<br>
            </td>
            <td class="name-col">{{file.progress}}</td>
          </tr>
          <tr>
            <td colspan="2">
              {{otherFile[$index].errors}}
            </td>
          </tr>
       </div>
    

    【讨论】:

    • 在这种情况下,otherFile 如何知道迭代 otherFiles?
    • 您必须在处理 html 的方式上发挥创意,但请查看我对帖子所做的编辑,我认为您可以了解要点。
    猜你喜欢
    • 2013-08-11
    • 1970-01-01
    • 2016-12-26
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多