在 angularjs 中,当我没有键值时,如何遍历 JSON 来填充值?

In angularjs how do I iterate through JSON to fill in values when I don't have a key value?

我有以下数据结构:

{
"0": {
"keyword": "lawn",
"short_desc": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"pt_value": "10"
},
"1": {
"keyword": "lawn",
"short_desc": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"pt_value": "10"
},
"2": {
"keyword": "lawn",
"short_desc": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"pt_value": "10"
},
"3": {
"keyword": "lawn",
"short_desc": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"pt_value": "10"
},
"4": {
"keyword": "lawn",
"short_desc": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"pt_value": "10"
},
"5": {
"keyword": "lawn",
"short_desc": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"pt_value": "10"
}
}

我需要像这样 运行 ng-repeat:

<div ng-controller="myController">
    <div ng-repeat="SOMETHING">
        <p>{{ desc }}</p>
        <p>{{ points }}</p>
    </div>
</div>

显然我可以 运行 像 ng-repeat="product as products" 这样简单的东西,那么我如何遍历数据、重复并将内容放在我需要的地方?

您可能想看一下 syntax of ng-repeat expressions,您仍然可以使用对象管理重复。

假设scope.items表示问题中的对象:

<div ng-controller="myController">
    <div ng-repeat="(k, item) in items">
        <p>{{ item.short_desc}}</p>
        <p>{{ item.pt_value}}</p>
    </div>
</div>

(key, value) in expression – where key and value can be any user defined identifiers, and expression is the scope expression giving the collection to enumerate.