【问题标题】:get single value from object array in angularjs从angularjs中的对象数组中获取单个值
【发布时间】:2017-02-19 00:49:40
【问题描述】:

我知道有很多解决方案可以从对象数组中获取单个值。但我认为必须有一种无需显式函数即可直接访问值的方法。

我在 nodejs 中有一组用户,我将它们发送到前端并通过result.data 获取,但我只想在控制台中打印所有用户的 objectName。

[{"objectName":"cn=anna,ou=user,ou=system",
"sn":["1"],
"cn":["test1"],
"objectClass":["top","inetOrgPerson","person","organizationalPerson"],
"userPassword":["password"],
"uid":["12345"]},

{"objectName":"cn=tim, ou=user,ou=system",
"sn":["2"],
"cn":["test2"],
"objectClass":["top","inetOrgPerson","person","organizationalPerson"],
"userPassword":["password"],
"uid":["125342"]}
]

有解决办法吗?像console.log(result.data.objectName) ..?

【问题讨论】:

  • 如果你想访问多个而不是。没有函数就无法完成

标签: angularjs arrays node.js object


【解决方案1】:

试试这个:

console.log(result.data.map(function(el){ return el.objectName }).toString());

【讨论】:

    猜你喜欢
    • 2016-09-27
    • 1970-01-01
    • 2020-05-08
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-23
    相关资源
    最近更新 更多