在“ng-options”选择列表中编辑所选选项文本
问题描述:
我需要将文本"(Default)"
添加到选定选项文本。请帮助我...在“ng-options”选择列表中编辑所选选项文本
该文本应该是“签证1881(默认)”。
但它只显示"Visa 1881"
。这里是我的代码:
<select ng-options="item.brand + ' ' + item.last_digits for item in approvedinvoicesCtrl.current_job.cards" ng-model="approvedinvoicesCtrl.GetCard"></select>
var vmc = this;
vms.current_job = response.data.payment_info;
for (var i = 0; i < vmc.current_job.cards.length; i++){
if (vmc.current_job.cards[i].is_default){
vmc.GetCard = vmc.current_job.cards[i] + ' (Default)';
}
}
我得到的是this,
而我需要的是this。
感谢。
答
尝试使用ng-init
默认值来初始化:
<select ng-init=" approvedinvoicesCtrl.GetCard = initialValue"
ng-model="approvedinvoicesCtrl.GetCard"
ng-options="item.brand + ' ' + item.last_digits for item in approvedinvoicesCtrl.current_job.cards">
</select>
更新时间:
的jsfiddle链接:
https://jsfiddle.net/avnesh2/g2j6863a/6/
工作,只要你想。
希望这会起作用。
答
在你if()
声明,你分配一个值cards[i].is_default
而不是评估它。所以不仅你的条件将永远是true
,cards[i].is_default
的价值也将是(String) "true"
。
if (this.current_job.cards[i].is_default = 'true')
// Should be
if (this.current_job.cards[i].is_default == 'true')
您应该使用==
,而不是=
。
你想要的文字option
是Visa 1881 (Default)
而不是Visa 1881
?
在这种情况下,你可以串只需添加到值:
this.GetCard = this.current_job.cards[i] + ' (Default)';
请参阅使用'jsfiddle'链接更新答案所需。 –
我想签证333 +(默认)像这个兄弟.... –
我编辑我的邮政检查 –