如何使用NG-重复在AngularJs词典? [英] How to use ng-repeat for dictionaries in AngularJs?

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

问题描述

我知道,我们可以轻松地使用的 NG-重复的对JSON对象或数组,如:

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

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

但如何使用NG-重复的字典,例如:

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/

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

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