【发布时间】:2016-05-01 22:50:34
【问题描述】:
我需要创建一种我无法检索某些值的哈希图。情况就是这样;
我有一个带有一些属性的 json:
$scope.getItems = {
"data": [{
"label": "first-label",
"objects": [{
"name": "firstObj",
"attributes": [{
"attrname": "Item1",
"attrValue": "",
"attrType": "text"
}, {
"attrname": "Item2",
"attrValue": "",
"attrType": "text"
}]
}],
"properties": {
"film:property": "action"
}
},
{
"label": "second-label",
"objects": [{
"name": "firstObj",
"attributes": [{
"attrname": "Item1",
"attrValue": "",
"attrType": "text"
}, {
"attrname": "Item2",
"attrValue": "",
"attrType": "text"
}]
}],
"properties": {
"film:property": "action"
}
},
{
"label": "third-label",
"objects": [{
"name": "firstObj",
"attributes": [{
"attrname": "Item1",
"attrValue": "",
"attrType": "text"
}, {
"attrname": "Item2",
"attrValue": "",
"attrType": "text"
}]
}],
"properties": {
"film:property": "drama"
}
},
{
"label": "fourth-label",
"objects": [{
"name": "firstObj",
"attributes": [{
"attrname": "Item1",
"attrValue": "",
"attrType": "text"
}, {
"attrname": "Item2",
"attrValue": "",
"attrType": "text"
}]
}],
"properties": {
"film:property": "action"
}
},
{
"label": "fifth-label",
"objects": [{
"name": "firstObj",
"attributes": [{
"attrname": "Item1",
"attrValue": "",
"attrType": "text"
}, {
"attrname": "Item2",
"attrValue": "",
"attrType": "text"
}]
}],
"properties": {
"film:property": "comic"
}
}
]
};
好吧,现在,我需要的是film:property 和label。
正如您在电影中看到的那样:财产“动作”我们拥有不止一个标签和精确度:
- first-label
- second-label
- fourth-label
所以一个假设的树视图可能是:
- action
- first-label
- second-label
- fourth-label
-drama
- third-label
-comic
-fifth-label
我在这里做了一个 jsfiddle:https://jsfiddle.net/vuqcopm7/58/,其中有相同的 json 和这样的列表:
<ul data-ng-repeat="object in uniqueNames">
<li ng-click="getLabelByProp(object)">
<a style="cursor:pointer">{{object}}</a>
</li>
</ul>
我需要的是当我点击一个项目时获取具有该属性的标签。例如:
点击动作,我需要显示在某个地方,在哪里并不重要,
- first-label
- second-label
- fourth-label
以此类推。感谢您的帮助!
【问题讨论】:
标签: javascript jquery angularjs json hashmap