0
我想根據輸入的合同號碼更新一組字段,用戶可以選擇想要更改的字段,並可以設置值。我的代碼沒有改變記錄,我不知道爲什麼。我猜想原因可能是道具沒有定義。該應用程序是建立在使用AngularFire的API,我的代碼如下:
<div class="container-fluid">
<div class="row">
<h3>Contract renewal & Group update other fields</h3>
<form class="form-horizontal" ng-submit="groupUpdate()" name="contractupdateForm">
<div class="form-group">
<label for="washroom" class="col-sm-2 control-label"> Contract Number</label>
<div class="col-sm-8">
<div class="input-group">
<input type="text" class="form-control" placeholder="Enter contract number so related fileds could be group updated" ng-model="contractupdate" ng-required="true">
</div>
</div>
</div>
<div class="form-group">
<label for="washroom" class="col-sm-2 control-label"> Fields Category</label>
<div class="col-sm-8">
<div class="input-group">
<select class="form-control" id="productfield" name = "productfield" ng-model="fieldupdate" ng-options="f.value as f.label for f in fields">
<option value="">No filed selected</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label for="washroom" class="col-sm-2 control-label"> Updated value</label>
<div class="col-sm-8">
<div class="input-group">
<input type="text" class="form-control" placeholder="Enter value supposed to be changed" ng-model="valueupdate" ng-required="true">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2">
<button type="submit" class="btn btn-default" >
Change group value
</button>
</div>
</div>
</form>
<hr>
</div>
</div>
控制器部分如下:需要從承諾鏈
$scope.groupUpdate = function(){
console.log($scope.contractupdate);
console.log($scope.fieldupdate);
console.log($scope.valueupdate);
for(var i = 0; i< productsInfo.length;i++){
if(productsInfo[i].productcontract == $scope.contractupdate){
var prop = $scope.fieldupdate;
productsInfo[i].prop = $scope.valueupdate;
productsInfo.$save(i).then(function(ref) {
console.log("group update success");
}, function(error) {
console.log("Error:", error);
});
}
/*if(i.productcontract == $scope.contractupdate){
var field = $scope.fieldupdate;
console.log(productsInfo[i].field);
productsList[i].field == $scope.valueupdate;
productsList.$save().then(function(productRef){
console.log("group updated success");
ref.key === obj.$id; // true
}, function(error) {
console.log("Error:", error);
});
}*/
};
};
您是否檢查JavaScript控制檯的任何錯誤消息? –
是的,我輸出productsInfo [i] .prop到控制檯,它是預期值,但記錄沒有改變,可能是我沒有使用保存功能吧? – dabeige
奇怪的是控制檯輸出「組更新成功」,如果$ save功能不起作用,那麼它不會返回一個承諾,但如果它已經工作,怎麼沒有結果被改變? – dabeige