kendo method:destroy 解决有些在kendo.all.js 的js 库里报错问题

首先,不得不承认,kendo UI 是个不错的东西,特别对于一个前端开发到行不足的程序猿来说。而在我们使用过程中貌似还是会遇到各种奇怪的问题。比如我们会经常用到对一些控件进行重赋值。

destroy

在kendo的configration 的Medhod 的描述是:

Prepares the widget for safe removal from DOM. Detaches all event handlers and removes jQuery.data attributes to avoid memory leaks. Calls destroy method of any child Kendo widgets.

其主要用来对之前的初始化信息进行销毁。防止再次初始化时报错。

当然如果我们仅仅是简单的使用其显示数据的话,一般是不会出现什么问题的。但是当我们如果想运用其更为复杂的一些功能接口时。要求就比较严谨点。

我们要注意的是kendo 的控件一般是不允许对其多次初始化。比如:在项目中,我们可能用到它的grid 或者 scheduler。 而且里面会有一些 功能接口。如:

<!DOCTYPE html>
<html>
<head>
    <base href="http://demos.telerik.com/kendo-ui/scheduler/events">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.1118/styles/kendo.common-material.min.css" />
    <link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.1118/styles/kendo.material.min.css" />
    <link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.1118/styles/kendo.material.mobile.min.css" />

    <script src="//kendo.cdn.telerik.com/2016.3.1118/js/jquery.min.js"></script>
    <script src="//kendo.cdn.telerik.com/2016.3.1118/js/kendo.all.min.js"></script>
    <script src="//kendo.cdn.telerik.com/2016.3.1118/js/kendo.timezones.min.js"></script>
    <link rel="stylesheet" href="../content/shared/styles/examples-offline.css">
    <script src="../content/shared/js/console.js"></script>
</head>
<body>
<div id="example">
    <div id="scheduler"></div>
    <div class="box wide">
        <h4>Console log</h4>
        <div class="console"></div>
    </div>
</div>
<script>
$(function() {
    function scheduler_dataBinding(e) {
        kendoConsole.log("dataBinding");
    }

    function scheduler_dataBound(e) {
        kendoConsole.log("dataBound");
    }

    function scheduler_save(e) {
        kendoConsole.log("save");
    }

    function scheduler_remove(e) {
        kendoConsole.log("remove");
    }

    function scheduler_cancel(e) {
        kendoConsole.log("cancel");
    }

    function scheduler_change(e) {
        var start = e.start; //selection start date
        var end = e.end; //selection end date
        var slots = e.slots; //list of selected slots
        var events = e.events; //list of selected Scheduler events

        var message = "change:: selection from {0:g} till {1:g}";

        if (events.length) {
            message += ". The selected event is ‘" + events[events.length - 1].title + "‘";
        }

        kendoConsole.log(kendo.format(message, start, end));
    }

    function scheduler_edit(e) {
        kendoConsole.log("edit");
    }

    function scheduler_add(e) {
        kendoConsole.log("add");
    }

    function scheduler_moveStart(e) {
        kendoConsole.log("moveStart");
    }

    function scheduler_move(e) {
        kendoConsole.log("move");
    }

    function scheduler_moveEnd(e) {
        kendoConsole.log("moveEnd");
    }

    function scheduler_resizeStart(e) {
        kendoConsole.log("resizeStart");
    }

    function scheduler_resize(e) {
        kendoConsole.log("resize");
    }

    function scheduler_resizeEnd(e) {
        kendoConsole.log("resizeEnd");
    }

    function scheduler_navigate(e) {
        kendoConsole.log(kendo.format("navigate:: action:{0}; view:{1}; date:{2:d};", e.action, e.view, e.date));
    }

    $("#scheduler").kendoScheduler({
        date: new Date("2013/6/13"),
        startTime: new Date("2013/6/13 7:00"),
        height: 400,
        timezone: "Etc/UTC",
        views: [
            "day",
            { type: "week", selected: true },
            "month",
            "agenda",
            "timeline"
        ],
        selectable: true,
        dataBinding: scheduler_dataBinding,
        dataBound: scheduler_dataBound,
        save: scheduler_save,
        remove: scheduler_remove,
        edit: scheduler_edit,
        add: scheduler_add,
        cancel: scheduler_cancel,
        change: scheduler_change,
        moveStart: scheduler_moveStart,
        move: scheduler_move,
        moveEnd: scheduler_moveEnd,
        resizeStart: scheduler_resizeStart,
        resize: scheduler_resize,
        resizeEnd: scheduler_resizeEnd,
        navigate: scheduler_navigate,
        dataSource: {
            batch: true,
            transport: {
                read: {
                    url: "//demos.telerik.com/kendo-ui/service/tasks",
                    dataType: "jsonp"
                },
                update: {
                    url: "//demos.telerik.com/kendo-ui/service/tasks/update",
                    dataType: "jsonp"
                },
                create: {
                    url: "//demos.telerik.com/kendo-ui/service/tasks/create",
                    dataType: "jsonp"
                },
                destroy: {
                    url: "//demos.telerik.com/kendo-ui/service/tasks/destroy",
                    dataType: "jsonp"
                },
                parameterMap: function(options, operation) {
                    if (operation !== "read" && options.models) {
                        return {models: kendo.stringify(options.models)};
                    }
                }
            },
            schema: {
                model: {
                    id: "taskID",
                    fields: {
                        taskID: { from: "TaskID", type: "number" },
                        title: { from: "Title", defaultValue: "No title", validation: { required: true } },
                        start: { type: "date", from: "Start" },
                        end: { type: "date", from: "End" },
                        startTimezone: { from: "StartTimezone" },
                        endTimezone: { from: "EndTimezone" },
                        description: { from: "Description" },
                        recurrenceId: { from: "RecurrenceID" },
                        recurrenceRule: { from: "RecurrenceRule" },
                        recurrenceException: { from: "RecurrenceException" },
                        ownerId: { from: "OwnerID", defaultValue: 1 },
                        isAllDay: { type: "boolean", from: "IsAllDay" }
                    }
                }
            }
        }
    });
});
</script>

</body>
</html>

如:上面code中的 scheduler_change()方法,我们在运用在会经常用它来实现切换日期时对scheduler的值进行重新初始化。但是如果我们直接对$("#scheduler").kendoScheduler({}) 进行调用时,可能会出现有些功能接口在kendo.all.js 里报错。

但如果我们在重新初始化前能调用一下destroy 方法。则可以避免这些问题。

var scheduler = $("#scheduler").data("kendoScheduler");
scheduler.destroy();

对之前的初始化进行销毁。

$("#scheduler").kendoScheduler({

时间: 2024-11-04 12:26:27

kendo method:destroy 解决有些在kendo.all.js 的js 库里报错问题的相关文章

[Android]通过js方法回调部分native报错 Web Console: Uncaught TypeError: Object [object Object] has no method &#39;xxx&#39;

在android4.2以前,注入步骤如下: webview.getSetting().setJavaScriptEnable(true); class JsObject { public String toString() { return "injectedObject"; } } webView.addJavascriptInterface(new JsObject(), "injectedObject"); Android4.2及以后,注入步骤如下: webv

如何解决linux下apache启动时httpd: apr_sockaddr_info_get() failed for 报错

今天在家里的RHLE5.5上安装apache的时候,先用user1用户./configure命令配置,然后才用root用户make && make install,结果apache起来的时候就报如下错误: httpd: apr_sockaddr_info_get() failed for bogon httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 fo

解决;R语言使用sqldf库是报错&quot;Failed to connect to database: Error: Access denied for user &#39;..&#39;@&#39;localhost&#39; (using password: NO) Error in !dbPreExists : invalid argument type&quot;

原因:在使用sqldf时,不需要加载RMySQL库 解决方案:在控制台执行释放RMySQL库加载 detach("package:RMySQL", unload=T); 解决;R语言使用sqldf库是报错"Failed to connect to database: Error: Access denied for user '..'@'localhost' (using password: NO) Error in !dbPreExists : invalid argume

解决python中&#39;chromedriver&#39; executable needs to be in PATH报错

在使用python中的selenium模块的时候出现以下错误 解决: 问题是没有Chrome 驱动,那么先下载驱动. 下载之前先查看自己chrome当前的版本信息: 点击chrome浏览器右上角的圆圈标记处,在帮助-->关于Google Chrome(E)中查看浏览器的版本信息 之后打开网址http://npm.taobao.org/mirrors/chromedriver/找到对应的版本,下载并解压到自己想放的路径中. 然后在代码中添加chromedriver文件路径 from seleniu

JS 调试中常见的报错的解决办法

报错:Uncaught SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse (<anonymous>) at Function.m.parseJSON (jquery.js:8515) at Object.success (crud.html:45) at j (jquery.js:3143) at Object.fireWith [as resolveWith] (jquery.js:3255) at x (

解决:mysql timestamp默认值0000-00-00 00:00:00 报错

一. 问题的引出 我们在用mysql5.7创建表时,如果把timestamp(时间戳)的默认值设置为0000-00-00 00:00:00 的形式,将会产生一条报错: `RepaymentDate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '回款日期', 报错信息如下: [Err] 1067 - Invalid default value for 'RepaymentDate' 二. 找出原因 这个问题和mysql中sql

[异常解决] Keil安装好nRF51822开发环境,运行DEMO报错:Error:“GPIOTE_CONFIG_NUM_OF_LOW_POWER_ENVENTS” is undefined

1.问题描述 when compiling "ble_app_proximity" exampled by Nordic, it indicates errors: "D:\Program Files\MDK5\ARM\PACK\NordicSemiconductor\nRF_Drivers\3.0.0\gpiote\nrf_drv_gpiote.c(30): error: #20: identifier "GPIOTE_CONFIG_NUM_OF_LOW_POWE

解决Myeclipse通过svn导入项目后,项目直接报错问题

在使用Myeclipse2015通过SNV导入项目后,项目直接报错,如下图: 点开后报错详细信息如下: Multiple markers at this line - The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files - The type java.lang.Exception cannot be resolved. It is indirect

解决CocosCreator 在微信小游戏中使用Socket.io 报错的问题

最近微信小游戏比较火,准备试着做一个Demo来玩一玩,网络通信这块就选择了socket.io,打包成微信工程,编译出现如下错误: 对于我这种菜逼(就目前的情况,自我感觉是挺菜的)来说,第一个想到的事情就是百度,百度不行,然后就谷歌,发现在cocos中文社区里面有很多人提到了这个问题,但是没有人回答,谷歌发现有大神重写了一套能够在微信小程序中使用的socket.io.emma..这些对于我来说,感觉太麻烦了,百度,谷歌无果,在回过头来仔细看看这个错误.提示io没有找到,竟然io没有找到,那我就给他