2015-10-16 51 views
0

我有一個問題,在angularjs中循環一個簡單的json與ng-repeat。 JSON的是這個:Angularjs不能使用ng-repeat循環,如果鍵有冒號「:」

$scope.lines = { 
     data: [ 
       { "properties": { 
        "name": "My test", 
        "test:testOne": "This is test one" } 
       } 
     ] 
    }; 

,問題是這樣的:test:testOne。我需要解析這個屬性,但我不知道它是如何做的,因爲它有冒號。我在這裏做了一個的jsfiddle:http://jsfiddle.net/7MhLd/1250/中,我嘗試了一些方法,但都沒有成功

+0

你是什麼意思你想解析'」測試:testOne「'? –

回答

2

您可以使用[]bracket notation,像這樣

<div ng-controller="MyCtrl"> 
    <div ng-repeat="line in lines.data"> 
     {{ line.properties['test:testOne'] }} 
     {{ line.properties.name }} 
    </div> 
</div> 

Example

+0

這就是我一直在尋找的東西。謝謝! –