【问题标题】:ng-repeat not working on Array of objects on directiveng-repeat 不适用于指令上的对象数组
【发布时间】:2017-07-13 18:38:41
【问题描述】:

我有一个directive,如下所示。变量testDataWithPlantNumberAsKey[plantnumber] 在父控制器中定义,其中包含数据。它是Objects 的数组。它由{{$parent.testDataWithPlantNumberAsKey[plantnumber]}} 在下面的代码中打印。 当我做 ng-repeat 时,它不起作用并且也不会抛出错误。我错过了什么?

<div id="test-data" class="test-data-table">
        <h3 style="text-align:center;" ng-if="!testDataWithPlantNumberAsKey[plantnumber]">No test Data</h3>

        {{$parent.testDataWithPlantNumberAsKey[plantnumber]}}
        <table ng-if="$parent.testDataWithPlantNumberAsKey[plantnumber]" class="left">
            <tr>
                <th>test</th>
                <th>Item Description</th>
                <th>Capacity</th>
                <th>Updated</th>
            </tr>
            <tr ng-repeat="data in $parent.testDataWithPlantNumberAsKey[plantnumber]  track by $index">
                <td>{{data.test}}

                </td>
                <td>{{data.itemDescription}}</td>
                <td>{{data.amount}}/{{data.testCapacity}}</td>
                <td>{{data.lastUpdatedDate | date :"h:mm" }}</td>
            </tr>
        </table>
    </div>

testDataWithPlantNumberAsKey[plantnumber] 如下所示

[{"plant_":" 0205","plantName":"Mrs. Edgardo Lockman LTD ","test":"1A ","item_":"30100060 ","itemDescription":"AC BASE 301 ","amount":0,"testCapacity":200,"plantCapacityPerHour":350,"plantCapacityPerShift":3000,"lastUpdatedDate":"2017-01-19T16:45:00","lasttestTransaction":251355},{"plant_":" 0205","plantName":"Mrs. Edgardo Lockman LTD ","test":"1B ","item_":"14800060 ","itemDescription":"AC SURFACE 448 TY 1 ","amount":0,"testCapacity":200,"plantCapacityPerHour":350,"plantCapacityPerShift":3000,"lastUpdatedDate":"2017-01-19T16:45:00","lasttestTransaction":251355},{"plant_":" 0205","plantName":"Mrs. Edgardo Lockman LTD ","test":"1C ","item_":"14800060 ","itemDescription":"AC SURFACE 448 TY 1 ","amount":0,"testCapacity":220,"plantCapacityPerHour":350,"plantCapacityPerShift":3000,"lastUpdatedDate":"2017-01-19T16:45:00","lasttestTransaction":251355}]

【问题讨论】:

  • 你能在定义 testDataWithPlantNumberAsKey[plantnumber] 的地方添加代码吗?
  • @Jenny 这是在显示这个指令的控制器内部。
  • 你检查过 testDataWithPlantNumberAsKey[plantnumber] 是数组吗?
  • 是的,这是一个数组。我已经检查了
  • 我已经在上面添加了数组,如果打印它,它会显示在指令中。我只是不能重复那个

标签: angularjs angularjs-directive angularjs-ng-repeat angular1.6


【解决方案1】:

好的,我遇到了问题,它使用 ng-if 创建了一个不同的范围,而 $parent 指的是前一个范围!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多