根据 Multi select 下拉列表中的 select/unselect 项更新数据库
update database based on select/unselect items in Multi select dropdown list
我有一个用 angular material 设计实现的多 select 下拉列表
它正在工作,它加载所有可能的选项(类别)并检查已经 selected 的项目。
我想根据此下拉列表中的 select/unselect 更新数据库。
我该怎么做?
<md-select ng-model="SelectedItems" multiple>
<md-option ng-repeat="item in Categories">{{item}}</md-option>
</md-select>
检查这个 ng-change directive
它会在你check/uncheck(函数)后立即获取控制器中的值,然后调用查询函数来更新数据库。希望对你有帮助。
仅以此为例,在 $scope.onChange 函数中编写更新代码
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
angular.module('MyApp', ['ngMaterial'])
.controller('MyCtrl', function ($scope) {
$scope.onChange = function(k) {
alert(k);
//your code here for storing in db
};
})
我有一个用 angular material 设计实现的多 select 下拉列表 它正在工作,它加载所有可能的选项(类别)并检查已经 selected 的项目。
我想根据此下拉列表中的 select/unselect 更新数据库。 我该怎么做?
<md-select ng-model="SelectedItems" multiple>
<md-option ng-repeat="item in Categories">{{item}}</md-option>
</md-select>
检查这个 ng-change directive
它会在你check/uncheck(函数)后立即获取控制器中的值,然后调用查询函数来更新数据库。希望对你有帮助。
仅以此为例,在 $scope.onChange 函数中编写更新代码
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
angular.module('MyApp', ['ngMaterial'])
.controller('MyCtrl', function ($scope) {
$scope.onChange = function(k) {
alert(k);
//your code here for storing in db
};
})