You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AngularJS select选中后int类型ID自动转为string类型问题

问题原因

你代码中option标签的ng-value={{x.jurisdictionID}}写法不符合AngularJS的绑定规则:ng-value本身是Angular内置的指令,支持直接绑定变量表达式,不需要额外加双大括号{{}}。加了双大括号后,Angular会先将x.jurisdictionID的计算结果强制转为字符串再赋值,所以原本的int类型ID就变成了string类型。
另外你写在select标签上的data-value=x.jurisdictionID是无效属性,下拉框的取值仅和ng-model、option的ng-value绑定逻辑有关,可直接删除。

修复方案

  • 方案一:仅修改ng-value的绑定写法,删除双大括号即可:
<select style="width:95%" class="form-control" 
      ng-model="m.jurisdictionID" 
      ng-change="buttonControll(); getFeeScheduleTips();">
      <option ng-repeat="x in m.jurisdictions | orderBy:'jurisdictionName'" ng-value="x.jurisdictionID">{{x.jurisdictionName}}</option>
</select>
  • 方案二:更推荐使用AngularJS原生的ng-options指令实现下拉框,性能优于ng-repeat生成option的写法,且能天然保留值的原始类型,代码更简洁:
<select style="width:95%" class="form-control" 
      ng-model="m.jurisdictionID"
      ng-options="x.jurisdictionID as x.jurisdictionName for x in m.jurisdictions | orderBy:'jurisdictionName'"
      ng-change="buttonControll(); getFeeScheduleTips();">
</select>

内容的提问来源于stack exchange,提问作者Rmixon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 16:15:02