Dojo:选择ComboBox并显示数据ID [英] Dojo : ComboBox selected and show data id
本文介绍了Dojo:选择ComboBox并显示数据ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有带数据的Dojo ComboBox
I have Dojo ComboBox with data
var store = new dojo.data.ItemFileReadStore( { data: {
identifier: "name",
items: [
{name:"Alabama", id:"AL"},
{name:"Alaska", id:"AK"},
{name:"American Samoa", id:"AS"},
{name:"Arizona", id:"AZ"},
{name:"Arkansas", id:"AR"},
{name:"Armed Forces Europe", id:"AE"},
{name:"Armed Forces Pacific", id:"AP"},
{name:"Armed Forces the Americas", id:"AA"},
{name:"California", id:"CA"},
{name:"Colorado", id:"CO"},
{name:"Connecticut", id:"CT"},
{name:"Delaware", id:"DE"}
]
}});
var comboBox = new dijit.form.ComboBox({
id: "stateSelect",
name: "state",
value: "-- Select --",
store: store,
searchAttr: "name"
}, "stateSelect");
我有文本框搜索数据ID。
and I have textbox to search data id.
然后我要选择(ComboBox)该数据。
并显示数据的id和值。
Then I want to selected(ComboBox) that data. And show the data id and value .
我如何做。
推荐答案
comboBox.item is
comboBox.item is a reference to the currently selected element.
您可以通过以下方式获取您的项目的ID和值:
You can get the id and value of your item through :
var id = store.getValue(comboBox.item, "id");
var name = store.getValue(comboBox.item, "name");
然后使用id和name在任何你需要的地方显示值...
Then you use id and name to display the values wherever you need to...
查看此jsfiddle的示例: http://jsfiddle.net/ psoares / RS2Z5 /
See this jsfiddle for an example : http://jsfiddle.net/psoares/RS2Z5/
这篇关于Dojo:选择ComboBox并显示数据ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文