在列表页面中编辑 MEANJS 列表

Edit MEANJS list in the list page

本文关键字:列表 编辑 MEANJS      更新时间:2023-09-26

我正在使用 MEAN JS,我正在尝试编辑列表页面上的列表项,但它显示错误如下。 我已使用ng-init="find()"启动数据作为列表,ng-init="findOne()"用于单个数据。

Error: [$resource:badcfg] Error in resource configuration for action `get`. Expected response to contain an object but got an array

.HTML下面是控制器内部的表单,它在其中启动 find() 和 findOne()。

<div ng-controller="OrdersController" ng-init="find()">
                <div> 
                    <div class="order-filter">
                        <div ng-repeat="order in orders">
                            <form ng-init="findOne()" name="orderForm" class="form-horizontal" ng-submit="update(orderForm.$valid)" novalidate>
                                <input type="text" class="" ng-model="order.title">
                                <input type="text" class="" ng-model="order.content">
                                <div class="form-group">
                                    <input type="submit" value="Update" class="btn btn-default">
                                </div>
                            </form>
                        </div>
                    </div>              
                </div>
            </div>

控制器

$scope.update = function (isValid) {
    $scope.error = null;
    if (!isValid) {
        $scope.$broadcast('show-errors-check-validity', 'orderForm');
        return false;
    }
    var order = $scope.order;
    order.$update(function () {
        $location.path('orders/' + order._id);
    }, function (errorResponse) {
        $scope.error = errorResponse.data.message;
    });
};
$scope.find = function () {
    Orders.query(function loadedOrders(orders) {
        orders.forEach(appendFood);
        $scope.orders = orders;
    });
};
$scope.findOne = function () {
        $scope.order = Orders.get({
            orderId: $stateParams.orderId
        });
    };

您需要检查您的订单服务,该服务可能正在使用$resource来提供您的API请求(Orders.query)

它应该看起来像这样:

function OrdersService($resource) {
    return $resource('api/orders/:orderId', {
      orderId: '@_id'
    }, {
      update: {
        method: 'PUT'
      }
    });
  }

样式可能会有所不同,具体取决于您使用的平均值版本。默认情况下,$resource查询需要一个结果数组,但如果由于某种原因您将"isArray"设置为 false,那么它将需要一个对象。

https://docs.angularjs.org/api/ngResource/service/$resource