如果我有类似的东西:
$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];
});
最佳答案
尝试改变
<li ng-repeat="thing in listOfAttributes">{{ whatever.thing }}</li>
至
<li ng-repeat="thing in listOfAttributes">{{ whatever[thing] }}</li>
关于javascript - 是否可以通过指定的对象属性列表进行ng-repeat,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32128615/