如何在 AngularJs 中为字典使用 ng-repeat? [英] How to use ng-repeat for dictionaries in AngularJs?

查看:29
本文介绍了如何在 AngularJs 中为字典使用 ng-repeat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们可以轻松地将 ng-repeat 用于 json 对象或数组,例如:

I know that we can easily use ng-repeat for json objects or arrays like:

<div ng-repeat="user in users"></div>

但是我们如何将 ng-repeat 用于字典,例如:

but how can we use the ng-repeat for dictionaries, for example:

var users = null;
users["182982"] = "{...json-object...}";
users["198784"] = "{...json-object...}";
users["119827"] = "{...json-object...}";

我想将它与用户字典一起使用:

I want to use that with users dictionary:

<div ng-repeat="user in users"></div>

有可能吗?如果是,我如何在 AngularJs 中做到这一点?

Is it possible?. If yes, how can I do it in AngularJs?

我的问题示例:在 C# 中,我们定义字典如下:

Example for my question: In C# we define dictionaries like:

Dictionary<key,value> dict = new Dictionary<key,value>();

//and then we can search for values, without knowing the keys
foreach(var val in dict.Values)
{
}

是否有一个内置函数可以像在 c# 中那样从字典中返回值?

Is there a build-in function that returns the values from a dictionary like in c#?

推荐答案

可以使用

<li ng-repeat="(name, age) in items">{{name}}: {{age}}</li>

请参阅ngRepeat 文档.示例:http://jsfiddle.net/WRtqV/1/

这篇关于如何在 AngularJs 中为字典使用 ng-repeat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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