我需要創建一種哈希表,我無法做到檢索某些值。這是情況;獲取將值傳遞給javascript的值
我有一個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
。 正如你所看到的電影:財產「行動」,我們有一個以上的標籤,exaclty:
- 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>
我需要的是當我點擊在項目與property.For例如獲得標籤:
在行動點擊我需要的地方顯示,它並不重要,因爲,
- first-label
- second-label
- fourth-label
等爲他人。感謝幫助!
是!感謝的人似乎正是我期待的! –