我在 ng-repeat 中有一个 Angular 进度条
<div ng-repeat="item in result">
<progressbar animate="false" value="item.status" type="success"><b>{{item.status}}%</b></progressbar></div>
但是我得到的结果变量为
$scope.result=[
{
id: 0,
name: "Abc",
status: "InProgress"
},
{
id: 0,
name: "Abc",
status: "InHold"
}
]
如何根据我的 JSON 数据(状态)为进度条内的变量“value”分配特定的数字。 即,如果状态为 InProgress,则值可以为 30。我只是希望根据状态有条件地获取值。
任何帮助将不胜感激。谢谢
最佳答案
您可以再编写一个函数,根据状态返回值
。
像这样
HTML
<div ng-repeat="item in result">
<progressbar animate="false" value="getStatusValue(item.status)" type="success"><b>{{item.status}}%</b></progressbar></div>
JS
$scope.result=[
{
id: 0,
name: "Abc",
status: "InProgress"
},
{
id: 0,
name: "Abc",
status: "InHold"
}
]
$scope.getStatusValue(st) {
if(st == "InProgress") {
return 30;
}
else if(st == "InHold") {
return 10;
}
}
它会起作用。
关于javascript - 将动态值绑定(bind)到 ng-repeat 内的进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26928133/