【问题标题】:Kendo UI does not call create if a function is specified如果指定了函数,Kendo UI 不会调用 create
【发布时间】:2013-08-14 10:08:42
【问题描述】:

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

我认为这是某种类型的配置错误,但我不知道问题出在哪里。

这是一个sn-p的代码:

    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' }
            }
        }
    }
});

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

    $('#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']
});

一些值得注意的行为:

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

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

【问题讨论】:

  • 尝试将所有传输方法定义为函数或 URL(都一样)。
  • 谢谢。我是根据stackoverflow.com/questions/14055230/… 的答案这样做的。把它清理干净了,现在我要弄清楚的是如何将读取模拟为一个带有函数的 URL。

标签: kendo-ui transport


【解决方案1】:

首先在transport 中创建一个 URL 或一个函数,不要混淆它们。
如果您需要将read 实现为一个函数,您只需这样做:

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

【讨论】:

  • 对 options.success 的调用绝对是一个谜。再次感谢。
猜你喜欢
  • 2014-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多