AngularJS-ng repeat不使用名为length和value 0的映射条目

AngularJS-ng repeat不使用名为length和value 0的映射条目,angularjs,nested,angularjs-ng-repeat,ng-repeat,Angularjs,Nested,Angularjs Ng Repeat,Ng Repeat,我想将带有从API获得的子事件的事件显示为JSON [ { "class":"de.ff.prg.EventItem", "id":27667, "additional_info":null, "comments":null, "event":{"class":"Event","id":27657}, "length":0, "runningorder":0, "screening":{"class":"Screening","id":27529}, "title_eng":"'71", "ti

我想将带有从API获得的子事件的事件显示为JSON

[
{
"class":"de.ff.prg.EventItem",
"id":27667,
"additional_info":null,
"comments":null,
"event":{"class":"Event","id":27657},
"length":0,
"runningorder":0,
"screening":{"class":"Screening","id":27529},
"title_eng":"'71",
"title_ger":"'71",
"venue":{"class":"Venue","id":1}},

{"class":"de.ff.prg.EventItem",
"id":27676,
"additional_info":null,
"comments":null,
"event":{"class":"Event","id":27657},
"length":5,
"runningorder":0,
"screening":null,
"title_eng":"NEW",
"title_ger":"NEW",
"venue":{"class":"Venue","id":8}
}
] 
为了在行而不是列中显示项目的字段,我用ng repeat嵌套了两个表,这样就得到了一个表的表

<!--Items-->
<table>
    <thead>
        <td colspan="6" style="background-color: #b9da73">
            <button class="btnAdd" ng-click="addAndEditEventItem()">Add Item</button>
        </td>
    </thead>
    <tbody>

        <tr ng-repeat="item in eventItems">
            <h1>{{eventItems.length}}</h1>
            <th>

            <table>
                <thead>
                    <td colspan="2" style="background-color: #c0da86">{{item.runningorder}}</td>
                    <td colspan="4" style="background-color: #c0da86">
                        <button class="btnAdd" ng-click="deleteEventItem(item.id)">Delete Item</button>
                    </td>
                </thead>
                <tbody>
                {{item}}
                    <tr ng-repeat="(key,value) in item">
                        <th colspan="2" style="background-color: #ceeca1">{{key}}</th>
                        <th colspan="4" style="font-weight: normal;">{{value}} </th>
                    </tr>
                </tbody>
            </table>

            </th>
        </tr>
    </tbody>
</table>

添加项
{{eventItems.length}
{{item.runningorder}
删除项目
{{item}}
{{key}}
{{value}}
到目前为止,这还没有问题,但在这一过程中,我已经失去了显示第一个子表主体的可能性(所有其他行都呈现良好)。我在body标记之前插入了
{{item}}
,它显示了缺少的数据,所以它就在那里

有什么想法吗?或者你需要看其他代码才能知道吗?我不知道

这是一个有趣的案例。 根据经验,我发现这是因为

"length":0
查看angular源代码,发现它将对象的属性在repeat中转换为数组,然后使用它的length属性对其进行迭代

...ngRepeatDirective...
              if (isArrayLike(collection)) {
                collectionKeys = collection;
                trackByIdFn = trackByIdExpFn || trackByIdArrayFn;
              } else {
                trackByIdFn = trackByIdExpFn || trackByIdObjFn;
                // if object, extract keys, sort them and use to determine order of iteration over obj props
                collectionKeys = [];
                for (key in collection) {
                  if (collection.hasOwnProperty(key) && key.charAt(0) != '$') {
                    collectionKeys.push(key);
                  }
                }
                collectionKeys.sort();
              }

              arrayLength = collectionKeys.length; <<<--- HERE

              // locate existing items
              length = nextBlockOrder.length = collectionKeys.length; <<<--- AND HERE
…ngRepeatDirective。。。
if(类isArrayLike(集合)){
collectionKeys=集合;
trackByIdFn=trackByIdExpFn | | trackByIdArrayFn;
}否则{
trackByIdFn=trackByIdExpFn | | trackByIdObjFn;
//如果是对象,则提取关键点,对它们进行排序,并用于确定obj道具的迭代顺序
collectionKeys=[];
用于(输入集合){
if(collection.hasOwnProperty(key)和&key.charAt(0)!=“$”){
收集键。按(键);
}
}
collectionKeys.sort();
}

arrayLength=collectionKeys.length;首先,你的HTML是无效的,你从
thead>tr>td
中错过了
tr
h1
不应该是
tr
的孩子,修复它,也许做一把小提琴或一把锤子来获得更好的图像这里有一把小提琴[(我的第一把小提琴)]()(也有问题补充)谢谢,我明天会做第一件事,我已经消除了关键,它的工作。我还检查了直接在服务器端outout上替换值。除0以外的任何值都可以。谢谢你提出了一个问题,我会解决它,直到它被修复。
for(var i = 0; i < $scope.eventItems.length; i++){
    $scope.eventItems[i].itemLength = $scope.eventItems[i].length;
    delete $scope.eventItems[i].length;
}