如果键有冒号,则Angularjs不能使用ng-repeat循环#34;:"

时间:2015-10-16 08:47:30

标签: javascript json angularjs angularjs-ng-repeat

我在使用ng-repeat的angularjs中循环一个简单的json时遇到了问题。 json就是这个:

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

问题是:test:testOne。我需要解析那个属性,但我不知道它是怎么做的,因为它有结肠。我在这里做了一个jsfiddle:http://jsfiddle.net/7MhLd/1250/其中我尝试了一些方法,但没有成功

1 个答案:

答案 0 :(得分:2)

您可以使用[] bracket notation,就像这样

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

Example