简体   繁体   English

根据多选下拉列表中的选择/取消选择项更新数据库

[英]update database based on select/unselect items in Multi select dropdown list

I have a multi select dropdown list implemented with angular material design and it's working, it loads all the possible options (Categories) and it checks the items selected already. 我有一个用角材料设计实现的多选下拉列表,它起作用了,它加载了所有可能的选项(类别),并检查了已选择的项目。

I want to update database based on select/unselect in this dropdown list. 我想基于此下拉列表中的选择/取消选择来更新数据库。 How can I do so? 我该怎么办?

<md-select ng-model="SelectedItems" multiple>
    <md-option ng-repeat="item in Categories">{{item}}</md-option>
</md-select> 

check this ng-change directive 检查此ng-change指令

It will get you the value in controller as soon as you check/uncheck (function) then call the query function to update the database. 选中/取消选中(函数)后,它将立即获得控制器中的值,然后调用查询函数以更新数据库。 Hope it helps. 希望能帮助到你。

just take this an example and write your update code with in $scope.onChange function 只是以这个例子为例,并在$ scope.onChange函数中编写您的更新代码

html html

 <div ng-controller="MyCtrl" layout layout-align="center center">
    <md-select ng-model="myModel" placeholder="Pick" ng-change="onChange(myModel)" >
        <md-option value="0">Zero</md-option>
        <md-option value="1">One</md-option>
    </md-select>
</div>

js js

angular.module('MyApp', ['ngMaterial'])
.controller('MyCtrl', function ($scope) {
    $scope.onChange = function(k) {
alert(k);
        //your code here for storing in db
    };


})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM