【问题标题】:dojo.connect in dojox.enhancedGrid plugin IndirectSelectiondojo.connect 在 dojox.enhancedGrid 插件 IndirectSelection
【发布时间】:2013-10-22 10:57:10
【问题描述】:

我偶然发现了一个奇怪的情况。

我们使用道场 AMD Vers。 1.9。其中dojo.connect被dojo.on取代

到目前为止一切正常。现在我想将一个事件监听器(选中复选框)连接到我的 EnhancedGrid 的 IndirectSelection-plugin。我用 dojo.on 搜索解决方案,但只找到 dojo.connect?!

正确吗?我的意思是 dojo.connect 在 dojo 1.9 中一般已被弃用?

这是我在 dojo 端找到的代码:

dojo.connect(grid.selection, 'onSelected'|'onDeselected', function(rowIndex){...})

参考:http://dojotoolkit.org/reference-guide/1.9/dojox/grid/EnhancedGrid/plugins/IndirectSelection.html#usages

这是我的代码:

if(!registry.byId("GraphGrid")){
        grid = new EnhancedGrid({
                    id: 'GraphGrid',
                    store: GraphicStore,
                    query: { ident: "*" },
                    structure: layout,
                    rowSelector: '20px',
                    keepSelection: false,
                    plugins: {
                        indirectSelection: {
                        headerSelector:false, 
                        width:"40px", 
                        styles:"text-align: center;"
                        }}                          
                    },"GridGraphicInMap");

                /*Call startup() to render the grid*/
                grid.startup();

                grid.on("rowClick", function(evt){
                    var idx = evt.rowIndex,
                        item = this.getItem(idx);
                    //  get a value out of the item
                    var value = this.store.getValue(item, "geom");
                    highlightGeometry(value,true);
                });

                dojo.connect(grid.selection, 'onSelected', getSelectedItems);

                }
                else {
                    setTimeout(function(){
                    grid.setStore(GraphicStore);
                    }, 1000);
                }...

我尝试将其更改为 dojo.on 或 grid.selection.on('Selected',getSelectedItems);但它不起作用。在这种特殊情况下 dojo.connect 仍然是正确的连接方式吗?

上面的代码运行良好,没有任何问题。

问候,米里亚姆

【问题讨论】:

  • dojo.connect(grid.selection, 'onSelected', function(rowIndex){ console.log(grid.getItem(rowIndex));//如果要获取选中的行});
  • 感谢您的回答,但我认为您误解了我的意思。我的意思是,你应该在任何地方使用 on('myThingy','click',doSomething);在这种情况下,您应该使用旧的 dojo.connect('myThingy',onClick,doSomething);我的问题是关于 dojo.connect 以及使用它是否正确,什么时候它通常被弃用。

标签: javascript events dojo grid


【解决方案1】:

您可以使用 dojo.connect 它不会影响事件触发。 并尝试通过以下方式使用您的连接:

 dojo.connect(grid, 'onSelected', getSelectedItems);

或 dojo.connect(grid, 'onselectionchanged', getSelectedItems);

如果其中任何一个不起作用,请告诉我。

【讨论】:

  • 感谢您的回答!我想我必须修改我的问题。上面的代码工作正常,这不是问题。问题是:为什么我应该在 dojo 1.9 中使用 dojo.connect,因为他们说它已被普遍弃用,您应该使用 dojo/on 来连接事件。仅在这种特定情况下。
  • 即使您使用不推荐使用的方法,它也不会影响您的代码,由您决定使用 dojo.connect 或 dojo/on。就像您拥有 android 3.0 或 4.4 一样,您的最新应用程序仍然可以在您的设备上运行,类似地连接或打开,您的方法将被调用。我正在使用 dojo v1.9.3,并且 connect 和 on 在我的代码中都可以正常工作。
  • 你当然是对的。正如我所说 - 它对我来说也很好。我只是想知道为什么 dojo 在这种情况下使用 connect 而不是 on。
猜你喜欢
  • 1970-01-01
  • 2011-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-05
  • 2014-06-05
  • 2011-03-01
  • 1970-01-01
相关资源
最近更新 更多