如果指定了功能,则Kendo UI不会调用create [英] Kendo UI does not call create if a function is specified

查看:100
本文介绍了如果指定了功能,则Kendo UI不会调用create的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Using Kendo.web.js versions 2013.2.716 and 2012.3.1315, I am trying to use a function in my transport.create rather than calling a URL. What I find is that the function does not get called. Instead a default URL is called and the resulting HTML appears to cause an error in the bowels of kendo because it is expected to be JSON instead.

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

I assume that this is some type of configuration error, but I can't figure out where the problem is.

以下是代码段:

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

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

Then I use the resulting data source to build a grid like this:

    $('#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的引用).
  • 当我关闭自动同步时,使用工具栏创建新项目时,网格将调用其编辑功能.当我打开自动同步时,不会调用编辑功能.而是运行数据源创建功能.

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

Any thoughts or insight on how I might be able to call a function instead of a URL will be appreciated.

推荐答案

首先在transport中制作所有作为URL或函数的内容,请勿混淆.
如果您需要将read实现为函数,只需执行以下操作:

First make in transport everything being an URL or a function, do not mix them up.
If you need to implement read as a function, you simply do:

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

这篇关于如果指定了功能,则Kendo UI不会调用create的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆