Dojo:访问dijit.form.Select中点击的项目? [英] Dojo: Getting access to the clicked item in a dijit.form.Select?
问题描述
我有一个dijit选择小部件,当用户点击其中一个下拉项目时,需要做一些事情。意义我需要访问点击的项目,以检索一些信息,并调用我自己的一个功能。
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.
我已经测试了在选择和我附加一个onChange可以获得文本值选择正确。但我需要对象而不是价值。该对象在数据信息属性中保存更多值。
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.
背景:这是一个通过服务器功能填充AJAX的打字头字段。有一个商店,但它是空的(据我所知),所以我不成功尝试: .store.fetchItemByIdentity
- 总是没有返回。
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)
}
})
我希望日志显示项目和请求对象,但它们都是未定义的。
ta.getValue()
按预期获取所选值。
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?
推荐答案
看看我的答案 onChange不足以触发Dojo Combobox的查询,还有一个 jsFiddle 。我添加了您需要的代码:
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);
});
这篇关于Dojo:访问dijit.form.Select中点击的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!