【发布时间】: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){...})
这是我的代码:
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