如果指定了函数,则Kendo UI不会调用create

Pro*_*gle 1 transport kendo-ui

使用Kendo.web.js版本2013.2.716和2012.3.1315,我试图在transport.create中使用一个函数而不是调用URL.我发现这个函数没有被调用.相反,调用默认URL并且生成的HTML似乎会导致kendo的内容出错,因为它应该是JSON.

我认为这是某种类型的配置错误,但我无法弄清楚问题出在哪里.

以下是代码片段:

    var clientListDS = new kendo.data.DataSource({
    transport: {
        read: {
            url: window.baseUrl + 'HealthCheck/ClientSummary',
            dataType: 'json',
            type: 'POST'
        },
        create: function(a,b,c) { alert('Create'); },
        createY: window.baseUrl + 'HealthCheck/DontCallMe',
        createX: {
            url: window.baseUrl + 'HealthCheck/DontCallMe',
            dataType: 'json',
            type: 'POST'
        },
        whatWeWantCreateToDo: function () {
            showChooseDialog('Some Random String', 'Select Client', OnRefreshInactiveClientList);
        },
        destroy: function () {
            alert('destroy');
        },
        update: function () {
            alert('update');
        }
    },
    autoSync: true,
    schema: {
        model: {
            id: 'ID',
            fields: {
                ID: { required: false, type: 'number', nullable: true },
                ClientName: { type: 'string' },
                ClientTag: { type: 'string' },
                Status: { type: 'string' }
            }
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

然后我使用生成的数据源来构建这样的网格:

    $('#cClientGrid').kendoGrid({
    dataSource: clientListDS,
    columns: [
        { field: 'ClientTag', title: 'Tag'},
        { field: 'ClientName', title: 'Name' },
        { field: 'Status' }
    ],
    editable: {
        mode: 'incell',
        createAt: 'bottom'
    },
    edit: function (pEvent) {
        if (pEvent.model.isNew())
            alert('create');
        else
            alert('Edit');
    },
    toolbar: ['create']
});
Run Code Online (Sandbox Code Playgroud)

一些值得注意的行为:

  • 您会在创建配置中看到多次尝试.如果我使用CreateY或CreateX,它将调用生成的URL.如果我使用Create或WhatWeWantCreateToDo,我最终将包含我的模式的每个元素的包含页面作为获取字符串项目下载(我假设这是某种类型的默认行为,因为我找不到对下载的URL的引用).
  • 当我关闭autoSync时,当我使用工具栏创建新项目时,网格将调用其编辑功能.当我打开autoSync时,不会调用编辑功能.相反,数据源创建功能运行.

任何关于我如何能够调用函数而不是URL的想法或见解将不胜感激.

Ona*_*Bai 7

首先使transport所有内容成为URL或函数,不要混淆它们.
如果您需要实现read一个功能,您只需:

transport: {
    read : function (options) {
        $.ajax({
            url: window.baseUrl + 'HealthCheck/ClientSummary',
            dataType: 'json',
            type: 'POST',
            success : function (result) {
                options.success(result);
            }
        });
    },
Run Code Online (Sandbox Code Playgroud)