如何在剑道中设置CRUD?

时间:2015-03-12 10:59:58

标签: javascript angularjs kendo-ui kendo-grid

如何在剑道中设置CRUD?更新和读取是可以的,但不创建。这是我这部分的代码:

 create: {
          url: function (data) {
            return $("#gatewayPath").data("value") + "odata/ods/ProcessProductionPerformanceMovements";
          },
          dataType: "json",
          type: "POST",
          beforeSend: function (x) {
            var auth = $("#authenticationType").data("value") + " " + $("#authenticationToken").data("value");
            x.setRequestHeader("Authorization", auth);
          }
        },

并在参数Map中我有:

if (operation === "create") {
             return '{ "_Key": "' + data._Key +
                '", "Comment": "' + data.Comment +
                '","MovementType": "' + data.MovementType +
                ((data.Unit) ? '","_UnitKey": "' + data.Unit._Key: "") +
                ((data.Material) ? '","_MaterialKey": "' + data.Material._Key: "") +  
                '","MaterialLotID": "' + data.MaterialLotID +
                '","Status": "' + data.Status +
                '","Quantity": "' + data.Quantity  +
                '","Description": "' + data.Description + 
                '","_UnitKey": "' + data._UnitKey + 
                '","_ProdPerfHeaderKey": "' + data._ProdPerfHeaderKey + 
                '","StockType": "' + data.StockType + 
                '","StockIndicator": "' + data.StockIndicator + 
                '","SAPStorageLocation": "' + data.SAPStorageLocation + 
                '"}';
          }

1 个答案:

答案 0 :(得分:1)

telerik.com上有一个创建示例。

var dataSource = new kendo.data.DataSource({
    transport: {
        /* the other CRUD settings are ommitted for brevity */
        create: function (e) {
            // batch is disabled
            // generate appropriate data item ID and save the new items to the original datasource
            e.data.my_ID_field_name = 123;
            // ...

            // on success return the new data items with IDs
            e.success(e.data);
            // on failure
            //e.error("XHR response", "status code", "error message");
        }
    } });