0
我通過函數動態使用數據加載,然後使用ng-repeat填充數據。ng-repeat顯示的數據不存在
下面是控制器代碼。
$scope.loadproducts = function(item_id) {
var pdata = $.param({
item_id : item_id,
});
$http({
method: 'POST',
url: baseurl + 'api/get_items_in_category_cart',
data: pdata,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function successCallback(response) {
$scope.items = response.data.products;
$scope.description = response.data.description;
console.log($scope.items);
$timeout(apply_tooltip, 500);
}, function errorCallback(response) {
});
};
查看
<div class="container col-md-6" ng-repeat="item in items">
<div class="panel panel-primary">
<div class="panel-heading">
<h4 class="panel-title">{{ item.title }}</h4>
</div>
<div class="panel-body">
<div class="col-md-3 col-xs-5"><a href="#" class="thumbnail"><img ng-src="{{ item.thumbnail }}"></a></div>
<div class="col-md-9" style="">
<div class="row">
<div class="col-md-12">
<span style="font-size: 14px; font-weight: 500;">{{ item.description }}</p>
</div>
</div>
<div class="row">
<div class="col-md-4 text-right" style=" text-align: left;">
<p>{{item.price | currency:"NZ $"}}</p>
</div>
<div class="col-md-8" style=" text-align: left;">
<input type="text" value="{{item.qty}}" style="width:50px; height: 28px; line-height: 28px;" readonly id="qty_{{item.id}}"/>
</div>
</div>
</div>
</div>
</div>
</div>
在初始頁面加載的代碼做的事情是應該做的。 有一個用戶進入另一個頁面的繼續按鈕。 如果用戶返回,這些項目應該重新加載。
問題是在重新加載期間應該顯示每個項目數量的文本框 - >> value =「{{item.qty}}」似乎顯示所有qty文本框的相同數量,而不管他們原來的數量。
console.log($ scope.items)顯示它應該具有的正確值。這只是顯示錯誤的數量。
任何想法的傢伙?
你的apply_tooltip是做什麼的? –
顯示懸停時的工具提示 –
您可以嘗試換行$ scope.items = response.data.products; $ scope.description = response.data.description;還有一個$ timeout(0)呢? –