从两个ng模型中获取数据并插入第三个ng模型onClick

时间:2015-08-09 14:17:56

标签: javascript angularjs angularjs-ng-model

Database SQL

App Front End

我有客户的价值在ng-model =“selectedCustomer”

我有订单的价值在ng-model =“selectedOrder”

我想在点击

的新ng-model =“dispatchPlan”中发送这些详细信息

我正在尝试运行此代码

        $scope.addSelectedOrder = function (selectedCustomer, selectedOrder) {

        angular.foreach(selectedCustomer.OrderDetails.ItemId, function (selectedCustomer, selectedOrder) {

            $scope.DispatchPlan.DispatchPlanDetail.CustomerId = selectedCustomer.CustomerId;
            $scope.DispatchPlan.DispatchPlanDetail.OrderId = selectedOrder.OrderDetails.OrderId;
            $scope.DispatchPlan.DispatchPlanDetail.ItemId = selectedOrder.OrderDetails.ItemId;
            $scope.DispatchPlan.DispatchPlanDetail.ApprovedQuantity = selectedOrder.OrderDetails.AprovedQuantity;
            $scope.DispatchPlan.DispatchPlanDetail.DeliveredQuantity = selectedOrder.OrderDetails.DeliveredQuantities[o.ItemId];
            $scope.DispatchPlan.DispatchPlanDetail.DeliverNow = selectedOrder.OrderDetails.DeliveredQuantity;

        });
    }

最后在数据库中发送此调度计划请检查附带的图像

1 个答案:

答案 0 :(得分:0)

在控制器中创建新模型

$scope.sendOrderDetail = {
    BusinessUnitId: "",
    OrderType: "",
    OrderId: "",
    DeliveryId: "",
    ItemDeliveryNo: "",
    ItemId: "",
    ApprovedQuantity: "",
    DeliveredQuantity: "",
    NewSupply: "",
    CreatedOn: "",
    CreatedBy: "",
    LastModifiedBy: "",
    LastModifiedDate: ""
}


$scope.sendOrder = {
    Status: "",
    BusinessUnitId: "",
    OrderType: "",
    OrderId: "",
    DeliveryId: "",
    VehicleNo: "",
    DriverName: "",
    DriverMobileNo: "",
    CreatedOn: "",
    CreatedBy: "",
    LastModifiedBy: "",
    LastModifiedDate: "",

    sendOrderDetail: []
}

从两种不同模型获取数据并插入最近创建的模型的函数

$scope.deliverOrder = function (recOrder, recOrderDetails, status) {

    $scope.sendOrder.Status = status; //Status Used for Warehouse Table

    $scope.sendOrder.BusinessUnitId = recOrder.BusinessUnitId;
    $scope.sendOrder.OrderType = recOrder.OrderType;
    $scope.sendOrder.OrderId = recOrder.OrderId;
    $scope.sendOrder.DeliveryId = "";
    $scope.sendOrder.VehicleNo = $scope.VehicleNo;
    $scope.sendOrder.DriverName = $scope.DriverName;
    $scope.sendOrder.DriverMobileNo = $scope.DriverMobileNo;

    $scope.sendOrder.CreatedOn = Date.now();
    $scope.sendOrder.CreatedBy = 1;
    $scope.sendOrder.LastModifiedBy = 1;
    $scope.sendOrder.LastModifiedDate = Date.now();

    var i = -1;

    angular.forEach(recOrderDetails, function (recOrder) {

        i++;

        $scope.sendOrderDetail.BusinessUnitId = recOrder.BusinessUnitId;
        $scope.sendOrderDetail.OrderType = recOrder.OrderType;
        $scope.sendOrderDetail.OrderId = recOrder.OrderId;
        $scope.sendOrderDetail.DeliveryId = "";
        $scope.sendOrderDetail.ItemDeliveryNo = "";
        $scope.sendOrderDetail.ItemId = recOrderDetails[i].ItemId;
        $scope.sendOrderDetail.ApprovedQuantity = recOrderDetails[i].ApprovedQuantity;
        $scope.sendOrderDetail.DeliveredQuantity = recOrderDetails[i].Quantity;
        $scope.sendOrderDetail.NewSupply = recOrderDetails[i].DeliveredNow;

        $scope.sendOrderDetail.CreatedOn = Date.now();
        $scope.sendOrderDetail.CreatedBy = 1;
        $scope.sendOrderDetail.LastModifiedBy = 1;
        $scope.sendOrderDetail.LastModifiedDate = Date.now();

        $scope.sendOrder.sendOrderDetail.push($scope.sendOrderDetail);

    });

    console.log($scope.sendOrder);

}