【问题标题】:ExtJS ComponentQuery and Dynamic contentExtJS ComponentQuery 和动态内容
【发布时间】:2016-06-13 23:45:35
【问题描述】:

我有一个包含多个网格的布局,它们都使用 RowEditing 插件。我正在尝试使用 Ext.ComponentQuery.query 来访问特定网格上的嵌入式 RowEditor 按钮,但无法弄清楚如何正确遍历事物。我想知道它是否与动态添加的 RowEditor 和按钮有关 - 尽管我找不到任何东西来确认是否符合预期。

编辑添加 jsfiddle http://jsfiddle.net/ttubbs/eadfpxao/

在每个网格中激活 RowEditing 后(双击每个网格中的一行),在控制台中运行以下命令会产生指示的结果...

Ext.ComponentQuery.query("roweditorbuttons") // two results
Ext.ComponentQuery.query("roweditorbuttons > #update") // two results
Ext.ComponentQuery.query("#grid1 > roweditorbuttons") // no results
Ext.ComponentQuery.query("#grid1 >  #update") // no results

Ext.ComponentQuery.query("roweditorbuttons > button[text=Update]") // two results

我需要能够执行以下操作,但查询不起作用:

Ext.ComponentQuery.query("#grid2 > #update") // give me the update button in #grid2
Ext.ComponentQuery.query("#update").up().itemId === "grid1" // determine which grid my button is in

问题是:

  • 给定一个网格 (#grid1[1]),如何访问行编辑器 纽扣?
  • 给定一个按钮 (#update[0]),我如何才能访问它 父网格?

【问题讨论】:

    标签: javascript extjs


    【解决方案1】:

    首先,在此示例中,您应该在网格中将itemId 更改为id。 “itemId”在您的示例中无关紧要。 假设您的网格有id=grid1,而您的roweditor 插件有pluginId=roweditor

    var plugin = Ext.getCmp("grid1").getPlugin("roweditor");
    // you can get the update button like this
    var updateBtn = plugin.editor.floatingButtons.down("button");
    // you can get the grid from the plugin as well
    var grid = plugin.grid;
    

    【讨论】:

    • 知道我错过了什么。但是,仍然不适合我。我已经更新了 jsfiddle 以包含 id,但也可以通过 itemId 获取组件。不要认为那部分太重要了。但是,鉴于组件 'Ext.getCmp("myGrid1").getPlugin("roweditor")' 返回未定义。 (“行编辑”也是如此)
    • 什么不起作用?我又试了一次,它奏效了。但是,您忘记将pluginId 提供给行编辑器。如果你不给它,你可以不带参数地调用 getPlugin() 。而且,浮动按钮只有在 roweditor 处于活动状态时才能实现。
    • 对,错过了这一步!这行得通,谢谢。 Ext.getCmp("myGrid2").getPlugin('rowEditor2').editor.floatingButtons.down("button")
    【解决方案2】:

    你好试试这个选择

    Ext.ComponentQuery.query('roweditorbuttons > button[text=Update]')[0]
    

    请找到截图。

    【讨论】:

    • 我需要从特定的网格中获取它。如果页面上有多个行编辑器处于活动状态,这仍然会给我多个按钮。
    猜你喜欢
    • 1970-01-01
    • 2013-08-10
    • 2015-06-28
    • 1970-01-01
    • 2011-07-20
    • 2015-08-17
    • 1970-01-01
    • 2012-04-27
    • 2012-11-15
    相关资源
    最近更新 更多