Angular UI-Grid POST/PUT RestFull 示例 API 通过 Angular ngResource
Angular UI-Grid POST/PUT Example on a RestFull API via Angular ngResource
显示网格运行良好:
FACTORY(摘录) 完美
.factory('MyResource', function($resource) {
return $resource(
'http://my-rest-api/whatever/:id',
{
id: '@_id'
},
{
update: {
method: 'PUT'
}
}
)})
CONTROLLER(摘录 1) 工作完美
$scope.myGrid.gridConfiguration = {..}
$scope.myGrid.columnDefs = {..}
$scope.myGrid.data = MyResource.query();
VIEW(摘录) 完美
<div
ui-grid="myGrid"
ui-grid-edit
ui-grid-cellNav
class="gridMid">
</div>
CONTROLLER(摘录 2)但更新不起作用:
$scope.myGrid.gridConfiguration.onRegisterApi = function(gridApi){
//set gridApi on scope
$scope.gridApi = gridApi;
gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
// Following works
$scope.msg.lastCellEdited = 'Edited (#' + rowEntity.id + '), Column: (' + colDef.name + ') New Value: (' + newValue + ') Old Value: (' + oldValue +")" ;
**// THIS DOES NOT WORK**
MyResource.update({id: rowEntity.id },rowEntity);
// following works too
$scope.$apply();
});
};
我哪里错了?
没有错误,REST-SERVER 没有正常工作。
对于所有想要使用 Angular UI-Grid 和 ngResource 测试 DUMMY-REST-API 的人,我在这里准备了一个存储库:
https://github.com/webia1/ANGULAR_SKELETON_VERTICAL_TABS
它使用 HTTP-PUT 更新资源。
显示网格运行良好:
FACTORY(摘录) 完美
.factory('MyResource', function($resource) {
return $resource(
'http://my-rest-api/whatever/:id',
{
id: '@_id'
},
{
update: {
method: 'PUT'
}
}
)})
CONTROLLER(摘录 1) 工作完美
$scope.myGrid.gridConfiguration = {..}
$scope.myGrid.columnDefs = {..}
$scope.myGrid.data = MyResource.query();
VIEW(摘录) 完美
<div
ui-grid="myGrid"
ui-grid-edit
ui-grid-cellNav
class="gridMid">
</div>
CONTROLLER(摘录 2)但更新不起作用:
$scope.myGrid.gridConfiguration.onRegisterApi = function(gridApi){
//set gridApi on scope
$scope.gridApi = gridApi;
gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
// Following works
$scope.msg.lastCellEdited = 'Edited (#' + rowEntity.id + '), Column: (' + colDef.name + ') New Value: (' + newValue + ') Old Value: (' + oldValue +")" ;
**// THIS DOES NOT WORK**
MyResource.update({id: rowEntity.id },rowEntity);
// following works too
$scope.$apply();
});
};
我哪里错了?
没有错误,REST-SERVER 没有正常工作。
对于所有想要使用 Angular UI-Grid 和 ngResource 测试 DUMMY-REST-API 的人,我在这里准备了一个存储库:
https://github.com/webia1/ANGULAR_SKELETON_VERTICAL_TABS
它使用 HTTP-PUT 更新资源。