gpt4 book ai didi

javascript - 使用 AngularJS 服务发布多个实体

转载 作者:行者123 更新时间:2023-11-28 06:06:50 24 4
gpt4 key购买 nike

我想使用 Angular JS 发布 2 个实体。

这是我的 AccountController.js

 $scope.InsertAccount = function (user,account) {
accountsService.InsertAccount(user,account);

};

我的AccountService.js

 var InsertAccount = function (user, account) {

return $http.post("http://localhost:26309/api/Compte/addUserV", {user :user, compte: account})
.then(function () {
$log.info("Insert Successful");
return;
});
};

我可以发布一个参数,但当我尝试添加多个参数时它不起作用。

最佳答案

您的意思是许多用户、许多帐户吗?通常,由于您要创建多个实体,因此您需要多个 POST。因此,辅助函数可能就是您正在寻找的:

$scope.InsertAccounts = function (users, accounts) {
return $q.all(users.map(function (user, n) {
return $scope.InsertAccount(user, accounts[n]);
}));
}

关于javascript - 使用 AngularJS 服务发布多个实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36777774/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com