如果我有类似的话:
$scope.listOfAttributes = ["someThings", "yetMoreThings"]
$scope.whatever = {
someThings: "stuff",
otherThings: "Also stuff",
yetMoreThings: "still stuff"
};
是否可以做这样的事情:
<ul>
<li ng-repeat="thing in listOfAttributes">{{ whatever.thing }}</li>
</ul>
或者我必须先处理它:
$scope.generatedObject = {}
$scope.listOfAttributes.forEach(function(thing)){
$scope.generatedObject[thing] = $scope.whatever[thing];
});
答案 0 :(得分:2)
使用括号表示法就像在普通的javascript代码中一样:
<ul>
<li ng-repeat="thing in listOfAttributes">{{ whatever[thing] }}</li>
</ul>
答案 1 :(得分:1)
尝试改变,
<li ng-repeat="thing in listOfAttributes">{{ whatever.thing }}</li>
到
<li ng-repeat="thing in listOfAttributes">{{ whatever[thing] }}</li>