所以,我有这个问题,我的数组集合中的属性发生了变化。这是我的控制器的代码片段:
$http({
method: 'GET',
headers: globalData.httpHeader,
params: {
orderkey:$scope.transaction.orderData.orderkey,
category:'ViewOrderDetail'},
url: globalData.APIARN+ globalData.StageVariable + globalData.OrderRes
}).then(function successCallback(response) {
$ionicLoading.hide();
if (response.data.errorMessage) {
swal({
title: "Ooops!",
text: "Problem Encountered in the Server. Please Contact Support."
});
} else {
$scope.itemDetails =response.data.order.orderdetail;
$scope.items = $scope.itemDetails;
angular.forEach($scope.itemDetails, function(value, key) {
$scope.itemKeys.push(value.productKey);
$scope.itemKey = $scope.itemKeys[$scope.itemKeys.length - 1];
$scope.itemKey++
$scope.itemAmountValues.push(value.quantity * value.unitPrice)
});
}
$scope.calcTotalAndProductAmt();
$scope.showItem = function(selectedKey){
$scope.selectedKeyItems = [];
angular.forEach($scope.itemDetails, function(value, key) {
if(value.itemKey == selectedKey){
$scope.selectedKeyItems.push(value)
}
});
}
console.log("before " + JSON.stringify($scope.items));
$timeout(function(){
console.log("after " + JSON.stringify($scope.items));
})
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
$ionicLoading.hide();
$scope.messageText = globalData.ProblemLoad;
swal({
title: "Ooops!",
text: $scope.messageText
});
}); // $http call
现在,控制台日志结果显示以下内容:
before [{"id":95,"productKey":"19","productName":"Roast Chicken","quantity":2,"unitPrice":175,"itemStatus":"OPEN"},{"id":96,"productKey":"14","productName":"Bolognese","quantity":3,"unitPrice":225,"itemStatus":"OPEN"},{"id":97,"productKey":"16","productName":"Coke","quantity":4,"unitPrice":50,"itemStatus":"CLOSE"},{"id":98,"productKey":"22","productName":"Rice","quantity":2,"unitPrice":45,"itemStatus":"OPEN"}]
transaction.js:1149
after [{"id":95,"productKey":"19","productName":"Roast Chicken","quantity":2,"unitPrice":175,"itemStatus":"OPEN","$$hashKey":"object:103"},{"id":96,"productKey":"14","productName":"Bolognese","quantity":3,"unitPrice":225,"itemStatus":"OPEN","$$hashKey":"object:104"},{"id":97,"productKey":"16","productName":"Coke","quantity":4,"unitPrice":50,"itemStatus":"OPEN","$$hashKey":"object:105"},{"id":98,"productKey":"22","productName":"Rice","quantity":2,"unitPrice":45,"itemStatus":"OPEN","$$hashKey":"object:106"}]
如您所见,可乐的itemStatus从“CLOSED”更改为“OPEN”。但是,我不知道值是如何变化的,因为我的控制器没有改变它的代码。我的HTML看起来像这样:
<div class="row" ng-repeat="item in items">
<div class="col col-60" ng-show="item.itemStatus='OPEN'" >
{{item}}
<label class="item item-input">
<select ng-model="item.productKey" ng-change="addPriceEdit(item)" ng-required="true">
<option ng-repeat="item in productskey" value="{{item.productkey}}" >{{item.productname}}</option>
</select>
</label>
</div>
<div class="col col-15">
<label class="item item-input">
<input type="number" ng-model="item.quantity" min="1" step="1" max="9999999999" ng-required="true" ng-change="calcTotalAndProductAmt()">
</label>
</div>
<div class="col col-15">
<label class="item ">
{{item.unitPrice}}
</label>
</div>
<div class="col col-10">
<button class="button button-assertive"
ng-disabled="item.itemStatus!='OPEN'"
ng-click="removeItem($index)">-</button>
</div>
</div>
任何人都知道出了什么问题?
答案 0 :(得分:0)
用 -
替换您的代码<div class="col col-60" ng-show="item.itemStatus=='OPEN'" >
因为,使用single =,您要为变量赋值(因此对于每个对象,它将更改itemstatus以打开)。为了比较,您应该使用==。