码迷,mamicode.com
首页 > Web开发 > 详细

angularJs select ng-options 绑定int型的时候绑定失效的坑

时间:2015-09-24 19:23:21      阅读:368      评论:0      收藏:0      [点我收藏+]

标签:

<select ng-model="editObj.AdType" ng-options=" type.id as type.name for type in adTypes "></select>

其中type.id是int,这样绑定后下拉框会生成。但是不管editObj.AdType的值是什么都无法绑定成功。

原因在于ng-options会把int型自动转成string。我们要把它转回来就可以了。

  <select ng-model="editObj.AdType" ng-options="convertToInt(type.id) as type.name for type in adTypes "></select>

$scope.convertToInt = function (id) {
return parseInt(id);
};

angularJs select ng-options 绑定int型的时候绑定失效的坑

标签:

原文地址:http://www.cnblogs.com/kklldog/p/4836122.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!