我需要从AngularJS SPA中的一系列资源中获取资源键。 我使用这样的资源:
var answers = $resource('/api/answers/:id', {id: '@id'})
它连接到我的node.js后端,后端从nstore加载JSON。 “API”只是从nStore数据库中获取数据,我只是按res.end(result)
发送我的结果:
{
"1moabd0c": {
"q1": "asdf",
"q2": "3",
"q3": [
"false",
"true"
],
"q4": "a@a.com"
},
"2loe5p5p": {
"q1": "edsds",
"q2": "3",
"q3": [
"false",
"true"
],
"q4": "sdfwe@mai.com"
}
}
当我给出一个参数(比如,从第一个对象调用“/ api / answers / 1moabd0c”)时,我只得到一个结果,如下所示:
{
"1moabd0c": {
"q1": "asdf",
"q2": "3",
"q3": [
"false",
"true"
],
"q4": "a@a.com"
}
}
那么如何提取该对象密钥呢?
我在视图中使用资源:
tbody
tr(ng-repeat='answer in answers')
td {{answer.q4}}
td
a(href='#/answers/{{answer.key}}') Open
但它不起作用。我尝试使用{{asnwer.key}},{{answer.id}}那里......还有什么可以用来获取哈希?
编辑:当我在我的控制器中执行此操作时:
$scope.answers = Answers.query()
window.x = $scope.answers;
然后在窗口我注销x,我得到一个数组,但该数组有$$hashKey
道具。我猜这些是角度自己的哈希键。我需要原始的。数组看起来像这样(编辑它有点适合这里)
[
{
"$$hashKey": "005",
"q1": "asdf",
"q2": "3",
"q3": [
"false",
"true"
],
"q4": "a@a.com",
__proto__: g /* Which seems to be the angular resource object literal, with $delete, $get and stuff */,
},
{
"$$hashKey": "009",
"q1": "Ovojejedanodgovor",
"q2": "4",
"q3": [
"false",
"true"
],
"q4": "babaa@a.com",
__proto__: g /* again this obj */
}
]