如何使用ng-repeat遍历AngularJS中的地图条目


67

您将如何遍历map中的条目,以便可以打印输入键和值?例如,我想做这样的事情:

<ul>
    <li ng-repeat='mapEntry in {"First Name":"John", "Last Name":"Smith"}'>
        <span>Key: {{mapEntry.key}}, value: {{mapEntry.value}}</span>
    </li>
</ul>

3
如果要遍历一个实际的Map,这个问题可以解决这个问题:stackoverflow.com/questions/44073208/…–
Mel

Answers:


149

文档中,我发现此语法有效:

<ul>
    <li ng-repeat='(key, value) in {"First Name":"John", "Last Name":"Smith"}'>
        <span>Key: {{key}}, value: {{value}}</span>
    </li>
</ul>
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.