【发布时间】:2015-09-27 19:56:10
【问题描述】:
我只想保存多个复选框中包含的值,前提是它们被选中。它们将使用 php 保存到 MySQL 数据库中。这是我的 HTML 代码。
<div class="panel" ng-controller="checkBoxController">
<input class="form-control" placeholder="Cherchez vos contacts" type="text" ng-model="searchText">
</br>
<div ng-repeat="employee in employees | filter:searchText ">
<label class="action-checkbox">
<input id="{{employee.name}}" type="checkbox" value="{{employee.name}}" ng-checked="selection.indexOf(employee.name) > -1" ng-click="toggleSelection(employee.name)">
</label>
<label for="{{employee.name}}"></label>
{{employee.name}}
</label>
</div>
</br>
<span class="selected-item">Destinataires choisis:<span>
<div ng-repeat="name in selection" class="selected-item">
{{name}}
</div>
</div>
这是我的 JS 代码。
var myApp = angular.module('myApp', []);
myApp.controller('checkBoxController', function($scope, $http) {
$http.get("information.php")
.success(function (response) {
$scope.employees = response.records;
});
$scope.selection = [];
// toggle selection for a given employee by name
$scope.toggleSelection = function toggleSelection(employeeName) {
var idx = $scope.selection.indexOf(employeeName);
if (idx > -1) {
$scope.selection.splice(idx, 1);
} else {
$scope.selection.push(employeeName);
}
};
});
下一步是什么?也许保存在 JSON 文件中并通过 HTTP post 发送?我迷路了。
【问题讨论】:
-
您使用
$http.get从 php 获取员工数据。您可以使用$http.post将数据发送到 php。所以基本上以$http.post("myfile.php", {selection: $scope.selection})为例。 -
您可以简单地收集表单数据并将其发送到所需的 php 文件,然后执行插入检查这个小提琴jsfiddle.net/YGQT9
-
对不起,我试过了,但我在我的 php 页面中收到了注释。
标签: javascript php mysql angularjs