我已經按照js-data角度教程在我當前的項目中設置了js-data-angular。JS數據加載數據,但不會在視圖中呈現
模型定義:
.factory('shipmentFactory',
function(DS) {
return DS.defineResource({
name:'ShipmentInstructions',
idAttribute:'id',
basePath:'apiEndpoint'
}
);
}).run(function (shipmentFactory){})
在我的控制器:
.controller('ShipListCtrl', function($scope,shipmentFactory) {
shipmentFactory.findAll().then(function(shipmentInstructions){
$scope.shipments = shipmentInstructions;
console.log($scope.shipments)
});
});
在我看來,我嘗試使用NG-重複,但沒有在返回的對象進行迭代顯示。我知道我的端點被擊中並且數據被返回,因爲my console displays the returned shipment object。
該教程提到了如何將數據加載到視圖中,但看起來像那些使用ngRoute的人。我在當前項目中使用ui-router,並在嘗試解決該狀態下的資源時遇到更多挑戰。
該資源用於包含在另一個視圖中的視圖 - 該狀態的模板視圖。
只是尋找一些方向,如何讓我的數據在我的視圖中顯示,請提前謝謝。
修訂貨物模型:
.factory('shipmentFactory',
function(DS) {
return DS.defineResource({
name:'ShipmentInstructions',
idAttribute:'id',
basePath:'apiEndpoint',
cacheResponse: true,
afterFindAll: function(data, cb){
//extract the array from that nested property
shipmentsArray = [];
//forloop to push every item returned to
for(var i = 0; i < data.shipmentInstructions.length; i++){
shipmentsArray.push(data.shipmentInstructions[i]);
}
cb(null,shipmentsArray)
}
}
);
}).run(function (shipmentFactory){})/*makes sure shipmentFactory gets defined*/
在設置了'$ scope.shipments'變量後,嘗試'$ scope。$ apply()' –
我相信將它發送到摘要循環 – qmarcelle