Javascript中Dictionary的访问列表
Access list of Dictionary in Javascript
我有一个字典项列表,我想用Javascript访问它们。我该怎么做?这是一个ajax结果,result.d给出了列表。(ListItem1、ListItem2、ListItem3)如果我使用结果。ListItem1[0]我得到了值。我怎样才能拿到钥匙?
result.ListItem1[0].key
或result.ListItem1[0]['key']
将"密钥"替换为您实际想要访问的任何密钥。
您可以枚举对象的所有属性
var prop, result = {
d: {
ListItem1: ['value1'],
ListItem2: ['value2'],
ListItem3: ['value3']
}
};
for (prop in result.d) {
if (result.d.hasOwnProperty(prop)) {
console.log(result.d[prop]);
}
}
在日志中,您将看到3个数组值
感谢您的回复。我使用以下内容来访问字典的密钥:
for (t in result.ListItem1)
{
type = result.ListItem1[t];
typeId = t;
alert(t);
o.push('<option value="');
o.push(t);
o.push('" class="chz-option">');
o.push(type);
o.push('</option>');
}
$('#type').html(o.join(''));
相关文章:
- 使用js或extjs访问对象的java列表
- Javascript中Dictionary的访问列表
- jQuery访问列表视图->ul->李->span->img
- 访问可扩展QML应用程序中的列表视图索引
- D3.js~有没有办法在下拉列表中访问csv标题值
- 访问knockout.js选择列表中的值时出现问题
- 通过访问Ember.ArrayController获取话语中徽章的列表
- 循环访问本地存储中的 json 列表
- 使用 chui.js $.当有两个列表时,UI 可访问
- 在 jQuery 中从某个索引循环访问列表到另一个索引
- 循环访问列表并获取元素映像 ID
- 如何从 setInterval 访问列表中的动态内容
- 使用Javascript访问列表项中的表单元格数据
- 使用JQuery访问列表的元素
- 无法在JavaScript中从Flask模板变量中访问列表元素
- 在javascript中访问列表元素
- AngularJS中的文件访问列表
- 在JavaScript中访问C#列表变量
- 如何在Javascript中从JSP访问列表
- JQuery UI对话框按钮如何访问列表的选定值