angularjs select标签使用ng-repeat标签之后,ng-model无法更新问
发布时间:2020-12-17 08:35:44 所属栏目:安全 来源:网络整理
导读:angularjs select标签使用ng-repeat标签之后,ng-model无法更新问题,百度了一下没有发现原因,后来采用了jquery的方式进行首次赋值,如下过程: 我也遇到过这样的问题,由于option是使用ng-repeat生成的,ng-model首次并没有更新,后来采用了jquery的方式,给select
angularjs select标签使用ng-repeat标签之后,ng-model无法更新问题,百度了一下没有发现原因,后来采用了jquery的方式进行首次赋值,如下过程: 我也遇到过这样的问题,由于option是使用ng-repeat生成的,ng-model首次并没有更新,后来采用了jquery的方式,给select设置一个id,然后使用jquery的方式赋值,如下: html代码: <select ng-model="upName" id="up_name" > <option value="">无</option> <option ng-repeat="familyName in familyNames track by $index" value={{familyName}}">{{familyName}}</option> </select> js代码: setTimeout(function () { $("#up_name").val($scope.upName); },200); 这里有一个必须延迟一下才能赋值成功,我猜测是因为ng-repeat执行在后面,导致ng-model无法更新,有知道的前辈可以告诉我怎么处理 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |