I am using grails select dropdown element. I need to set default value for select2 dropdown options while click edit option in a form using angularjs..when i click edit button, then i have fetch related data for that form and update to form fields value as json object..Now normal text fields has been updated successfully.but select-2 dropdown fields doesn't updated to current value as selected.What's wrong with my code..here i have set common name for form model and object key like object key name and ng-model name are same for all datas..
谢谢先进。。
用于更新表单字段的我的对象:
Object {id: 3, name: "uday", code: "1", moveTaskType: "SPOT", priority: 1…}
我的表格 select2 代码:
<g:select id="moveTaskType" name="moveTaskType" from="${com.aa.fsight.MoveTaskRuleDef.MoveTaskType.class.getEnumConstants().collect{[name:it.name(), type: it.type]}}" optionKey="name" optionValue="type" class="select2 multiSelect" noSelection="['':'None']" ng-model="taskCreateForm.moveTaskType" />
我的 Controller 数据更新代码:
$scope.taskCreateForm=data;
最佳答案
为什么不使用 angularjs 的选择?您可以将属性直接与选项卡绑定(bind)并选择默认选择。
关于javascript - 如何使用angularjs json数据为选择2下拉菜单设置默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32602275/