【发布时间】:2016-05-05 00:55:59
【问题描述】:
所以我目前正在开发一个应用程序,它使用 WebAPI 和 AngularJS 从 SQL 表中搜索一些数据并将其显示在网页上供用户选择多个单独的数据行。我将选定的行插入到一个单独的 JSON 数组(可用客户端)中,我想将其插入到一个单独的 SQL 表中。对我来说,将我的 JSON 数据数组插入到不同的 SQL 表中的最佳方法是什么。我将附上我目前用来获取数据的代码。
Controller.js
var app = angular.module('myApp', []);
app.controller("myController", function ($scope, $http) {
function getCert(myid) {
$http.get('api/Cert/Get/', { params: { id : myid } })
.success(function (data) {
$scope.selectedclients = data;
})
}
$scope.searchClick = function() {
getCert($scope.myid);
}
$scope.moveItem = function (item, from, to) {
var idx = from.indexOf(item);
if (idx != -1) {
from.splice(idx, 1);
to.push(item);
}
};
$scope.availableclients = [];
});
HTML
<html data-ng-app="myApp">
<body data-ng-controller ="myController">
My_ID: <input type="text" ng-model="my_id" />
<input type="submit" value="Search" ng-click="searchClick()" />
<select size="10" multiple ng-model="selected" ng-options="i.unit_id for i in selectedclients" style="width: 400px"></select>
<div class="btn-group">
<button title="Remove From List" class="btn btn-default" ng-click="moveItem(available[0], availableclients,selectedclients)"><i class="glyphicon glyphicon-chevron-left"></i></button>
<button title="Add To List" class="btn btn-default" ng-click="moveItem(selected[0], selectedclients,availableclients)"><i class="glyphicon glyphicon-chevron-right"></i></button>
</div>
<select size="10" multiple ng-model="available" ng-options="i.unit_id for i in availableclients" style="width: 400px"></select>
</body>
</html>
我的代码工作正常我只是不知道如何获取我的可用客户端 JSON 数组并将其插入到我的 SQL 表中。这可能真的很容易做到,但我所有的搜索都对我正在寻找的内容一无所知。任何帮助表示赞赏。谢谢!
编辑 1:根据评论的建议,我添加了用于获取 Web API 的控制器。再次感谢您的任何建议!
public class CertController : ApiController
{
CertEntities objapi = new CertEntities();
[HttpGet]
public IEnumerable<AngularCoCSelect_Result> Get(int id)
{
return objapi.AngularCoCSelect(id).AsEnumerable();
}
}
【问题讨论】:
标签: javascript sql asp.net angularjs json