gpt4 book ai didi

javascript - 是否可以通过指定的对象属性列表进行 ng-repeat

转载 作者:行者123 更新时间:2023-11-30 12:17:13 25 4
gpt4 key购买 nike

如果我有类似的东西:

$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];
});

最佳答案

像在普通 javascript 代码中一样使用括号符号:

<ul>
<li ng-repeat="thing in listOfAttributes">{{ whatever[thing] }}</li>
</ul>

关于javascript - 是否可以通过指定的对象属性列表进行 ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32128615/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com