dijit / form /选择onSelect事件

时间:2014-04-16 14:23:55

标签: events dojo

是否有其他可以使用dojo / form / Select注册的事件,除了onChange?

每次用户选择一个选项时,我都需要执行一个回调函数,即使他选择了与上次选择的选项相同的选项。我尝试过的选项:onSelect,onClick不起作用。

        var spatialSelectionStore = new Memory({
        data: [
            { label: "Rectangle", id: "RECT" },
            { label: "Polygon", id: "POLY" },
            { label: "Circle", id: "CIRC" },
            { label: "Freehand", id: "FREE" }
        ]
    });

    var os = new ObjectStore({ objectStore: spatialSelectionStore });

    spatialQuerySelect = new Select({
        id: "selectionType",
        style: { width: "100px" },
        store: os,
        onChange: activateDrawTool
    }, "cp_selectByShapeId");
    spatialQuerySelect.startup();

2 个答案:

答案 0 :(得分:1)

我找到了一种方法来做到这一点,虽然它可能不是最好的方式,但似乎有效。

我设置了一个方面来在Select._setValueAttr函数执行后触发一个函数,每次单击菜单下拉列表或下拉项时,小部件都会触发该函数。因此,我添加了一个检查以确保函数回调仅在您单击菜单项时触发(即在菜单关闭后)。我还必须手动删除您添加到onChange的{​​{1}}回调,因为这会干扰该方面。

<强> HTML

Select

<强>的JavaScript

<div id="foo"></div>

<强> Fiddle

方面可能非常强大,但是如果你使用太多并过分依赖它们,你最终会得到一些可怕的混乱的意大利面条代码,所以我建议你谨慎使用它们,只在必要的时候。

如果您不熟悉他们的操作,您可以告诉某个方面触发require(["dojo/aspect", "dojo/store/Memory", "dijit/form/Select", "dojo/data/ObjectStore", "dojo/dom-construct", "dojo/dom", "dojo/aspect"], function(aspect, Memory, Select, ObjectStore, domConstruct, dom, aspect) { var spatialSelectionStore = new Memory({ data: [ { label: "Rectangle", id: "RECT" }, { label: "Polygon", id: "POLY" }, { label: "Circle", id: "CIRC" }, { label: "Freehand", id: "FREE" } ] }); var os = new ObjectStore({ objectStore: spatialSelectionStore }); spatialQuerySelect = new Select({ id: "selectionType", style: { width: "100px" }, store: os }, "cp_selectByShapeId"); spatialQuerySelect.startup(); aspect.after(spatialQuerySelect, "_setValueAttr", function() { if(spatialQuerySelect.dropDown.isShowingNow === false) { alert(spatialQuerySelect.get('value')); } }); domConstruct.place(spatialQuerySelect.domNode, dom.byId("foo"), "first"); }); beforeafter其他方法,方面将& #34;听&#34;使用函数回调激活该方法并使其正常运行。 Further documentation

答案 1 :(得分:0)

spatialQuerySelect.dropDown.on("execute",function() {
alert(spatialQuerySelect.get('value'));
});

这也适用于所有选项。

onExecute: function(){
            // summary:
            //      Attach point for notification about when a menu item has been executed.
            //      This is an internal mechanism used for Menus to signal to their parent to
            //      close them, because they are about to execute the onClick handler.  In
            //      general developers should not attach to or override this method.
            // tags:
            //      protected
        },