Dojo: Getting access to the clicked item in a dijit.form.Select?

元气小坏坏 提交于 2019-12-13 02:28:41

问题


I have a dijit Select widget and need to do something when the user clicks one of the dropdown items. Meaning I need access to the clicked item, to retrive some information, and call one of my own functions.

I've tested to attach an onChange on the select and I can get the text value selected fine. But I need the object and not the value. The object holds more values in a data-info-attribute.

Basically what I'm trying to achieve is to show one value in the list but send along more values to populate other fields when selected.

Background: This is a typeahead field populated thru AJAX by a server function. There IS a store attached but it's empty (as far as I can tell) so I've been unsuccessful trying with: .store.fetchItemByIdentity - always returns nothing.

ta.store.fetchItemByIdentity({
    identity: ta.getValue(),
    onItem: function(item, request){
        console.log(item),
        console.log(request)
    }
})

I expect the log to show item- and request-object, but they're both undefined. ta.getValue() get's the selected value as expected.

What's the best way to achieve this?


回答1:


Have a look at my answer to onChange not sufficient to trigger query from Dojo Combobox and also to jsFiddle mentioned there. I added code specific for your needs there:

select.dropDown.on("itemClick", function(dijit, event) {
    var node = dijit.domNode;
    console.log(domAttr.get(node, "data-info-attribute"));
    // or
    console.log(node.dataset.infoAttribute);
});


来源:https://stackoverflow.com/questions/12420956/dojo-getting-access-to-the-clicked-item-in-a-dijit-form-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!