我已经用了两个多星期的时间来解决我的问题,但是徒劳无功,我真的需要你的帮助,请... 在代码中,有ng-repeat,我必须更新ng-repeat显示的所有值的“frais”。我怎么能这样做,我正在使用angularJS和PHP
file.html
<ion-content class="padding" ng-controller="FactureAdminCtrl">
<ion-list ng-repeat = "selectedName in selected">
<div class="item item-divider center-text"
name="codeE" ng-model="selectedName.CodeEnvoiColis">
{{selectedName.CodeEnvoiColis}}
</div>
<label class="item item-input">
<input width="20%" type="text"
placeholder="Frais" ng-model="selectedName.FraisFact"
style="color:#BA1B1B;">
</div>
</label>
</ion-list>
<a class="button button-info" href="#/factureAdmin" `
ng-click=updateFact(selectedName)> Submit </a>
app.js
$scope.updateFact = function(selectedName){
$http.post(
"http://localhost/deb/updatFact.php",
{
'FraisFact':$scope.selectedName.FraisFact,
'CodeEnvoiColis':$scope.selectedName.CodeEnvoiColis,
}
).success(function(data){
alert(data);
});
}
updateFact.php
<?php
$CodeEnvoiColis = mysqli_real_escape_string($connect, $data->CodeEnvoiColis);
$FraisFact = mysqli_real_escape_string($connect, $data->FraisFact);
$query = "UPDATE colis SET FraisFact='$FraisFact' WHERE CodeEnvoiColis='$CodeEnvoiColis'" ;
?>
我该怎么办!
答案 0 :(得分:2)
如果要使用相同的PHP函数,请尝试以下操作:
将提交的ng-click功能更改为updateAll();
app.js
$scope.updateAll = function(){
// create an array of promises with request to save every single name
var promises = $scope.selected.map(function(name) {
return $http.post("http://localhost/deb/updatFact.php", {
'FraisFact':name.FraisFact,
'CodeEnvoiColis':name.CodeEnvoiColis,
})
});
// execute them all
$q.all(promises).then(function() {
console.log('All names are saved');
});
}