AngularJS - 如何在 ng-Repeat 中引用属性名称 [英] AngularJS - How can I reference the property name within an ng-Repeat

查看:29
本文介绍了AngularJS - 如何在 ng-Repeat 中引用属性名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了呈现对象中属性的值,我还想将属性名称呈现为标签.有没有办法用 ng-repeat 做到这一点?例如:

In addition to rendering the value of the properties in an object, I'd also like to render the property name as a label. Is there a way to do this with ng-repeat? For example:

<ul>
    <li ng-repeat="option in data">{{propertyName}}: {{option}}</li>
</ul>

可能会吐出这样的东西:

Which might spit out something like this:

<ul>
    <li>Name: John</li>
    <li>Phone: (123) 456-7890</li>
    <li>Country: England</li>
</ul>

推荐答案

试试这个:

<ul>
    <li ng-repeat="(key,val) in data">{{key}}: {{val}}</li>
</ul>

这篇关于AngularJS - 如何在 ng-Repeat 中引用属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆