我已经按照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