2013-12-17 42 views
0

我想實現的是僅當JSON對象內的子對象的值等於像'[]'的字符串時才顯示和元素。用angularJS檢查Json對象與字符串比較

我有JSON對象mytree.currentNode值

{ 
    "Name": "Three Numbers", 
    "ParentId": "3", 
    "children": [], 
    "selected": "selected" 
} 

我顯示的信息,我這樣做:

<span ng-show="mytree.currentNode.children == '[]'">Selected Item: {{mytree.currentNode.Name}}</span> 

但它不檢查「孩子」的值等於到「[]」
在此先感謝

+1

但JSON內的'children'值不是字符串'「[]」',它是一個數組'''''。你確定你不想'mytree.currentNode.children.length == 0'嗎? –

回答

4

"children": []不是字符串'[]'它的一個數組,所以檢查一個空數組像

mytree.currentNode.children.length == 0 
+0

亞..編輯答案 – Sarath

+0

+1或只是'!mytree.currentNode.children.length' – karaxuna

+0

它的工作正常,謝謝! – Seetha