剑道上的Kendo UI窗口单击第二次无法打开 [英] Kendo UI Window on grid button click does not open second time

查看:53
本文介绍了剑道上的Kendo UI窗口单击第二次无法打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事MVC Kendo Ui项目的工作,而我遇到以下问题:

im working on an MVC Kendo Ui project and i'm having the following problem:

我有一个带有自定义编辑按钮的可编辑剑道网格,该剑道在剑道窗口中打开部分视图,就像编辑器模板"一样.这似乎第一次正常工作,但是如果我关闭窗口并尝试编辑另一个项目,甚至相同的项目就无法正常工作.我认为,当我关闭窗口时,这消除了DOM中的元素,但无法弄清楚如何修复它.这是一些代码:

I have an editable kendo grid with a custom edit button wich opens a partial view on a kendo window wich acts like an "editor template". This seems to work fine first time but if i close the window and try to edit another item or even the same just does not work. I think that when i close the window this eliminate the elemment from the DOM but can't figure it out how to fix it. Here is some code:

@(Html.Kendo().Grid(Model)
      .Name("gridUbicaciones")
      .Columns(col =>
          {
              col.Bound(x => x.UbicacionId);
              col.Bound(x => x.Nombre);
              col.Bound(x => x.Latitud);
              col.Bound(x => x.Longitud);
              col.Bound(x => x.Altitud);
              col.Bound(x => x.Comentario);
              col.Command(cmd =>
                  {
                      cmd.Custom("Editar").Click("editItem");                     
                      cmd.Destroy().Text("Borrar");
                  }).Width(210).HtmlAttributes(new {style = "text-align:center;"});
          })
      .ToolBar(toolbar => toolbar.Create().Text("Agregar") )
      .Pageable()
      .Sortable()
      .Filterable()
      .DataSource(dsource => dsource
                                 .Ajax()
                                 .PageSize(8)
                                 .ServerOperation(false)
                                 .Model(model => 
                                     {
                                         model.Id(x => x.UbicacionId);
                                         model.Field(x => x.UbicacionId).Editable(false);
                                     })
                                 .Read(read => read.Action("Ubicaciones_Read", "Home").Type(HttpVerbs.Post))
                                 .Destroy(destroy => destroy.Action("Ubicaciones_Destroy", "Home"))
                                 .Update(update => update.Action("Ubicaciones_Update", "Home"))
                                 .Create(create => create.Action("Ubicaciones_Create", "Home"))
      ))
<div id="kendoWindowPopUp"></div>

JAVASCRIPT:

function editItem(e) {
    e.preventDefault();
    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
    if ($("#kendoWindowPopUp") == undefined)
        $("divUbicaciones").append("<div id=\"kendoWindowPopUp\"></div>");
    var windowObject = $("#kendoWindowPopUp").kendoWindow({
        resizable: false,
        modal: true,
        refresh: function () { this.center();},
        onClose: function () {

            windowObject.destroy();
            alert('hi close');// THIS CODE DOES NOT RUN
        }

    })
    .data("kendoWindow");



    windowObject.refresh({
        url: "/Home/EditorUbicacion?UbicacionId=" + dataItem.UbicacionId

    });
        windowObject.open();

}

我收到以下js错误:

未捕获的TypeError:对象[object Object]没有方法'kendoWindow'

Uncaught TypeError: Object [object Object] has no method 'kendoWindow'

预先感谢!

推荐答案

答案在注释中.在这里为像我这样的人通过google来添加它:).当通过AJAX加载的页面包含对jQuery的脚本引用时,通常会导致此问题.重新初始化jQuery时,将清除所有基于jQuery的数据属性,包括保存Kendo UI小部件对象的data(kendoWidget)属性.

The answer is in the comments. Adding it here for those like me hitting this through google :). This issue is usually caused when the page loaded via AJAX contains a script reference to jQuery. When jQuery is reinitialized, all jQuery-based data attributes are cleared, including the data(kendoWidget) attribute that holds the Kendo UI widget object.

  1. 请确保Window不会在页面上加载重复的jQuery实例.
  2. 使用'iframe'

  1. Please make sure that the Window does not load a duplicate jQuery instance on the page.
  2. Use 'iframe'

$("#dialog").kendoWindow({
   // load complete page...
   content: "/foo",
   // ... and show it in an iframe
   iframe: true
});

您可以在Telerik docs 此处中找到更多信息>

You can find more at Telerik docs here

这篇关于剑道上的Kendo UI窗口单击第二次无法打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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