开发者

the keyAttr of data-dojo-props doesn't work

开发者 https://www.devze.com 2023-03-27 17:12 出处:网络
here is my html file : ... <span data-dojo-id=\"staffStore\" data-dojo-type=\"dojo.data.ItemFileReadStore\" data-dojo-props=\'data:../../staff.json\'></span>

here is my html file :

...

<span data-dojo-id="staffStore" data-dojo-type="dojo.data.ItemFileReadStore" data-dojo-props='data:../../staff.json'></span>
<input data-dojo-type="dijit.form.ComboBox"
data-dojo-props="store: staffStore,
keyAttr: 'id',
searchAttr: 'staff_name',
autoComplete: true,
id: 'staff_name',
name:'staff_name',
value: '' "/>

...

and the json data goes as follows:

{
    identifier: "id";,
    label: "id",
    items: [{id: 982483700, staff_name: "guanyu";},{id: 582057769, staff_name: "zhangfei";},{id: 166802994, staff_name: "zhaoyun";}]
}

here is my problem: when i use post method i have got 'staff_name' in the searchAttr: 'staff_name' passed to the background-appication ,but i want to have the 'id' in the keyAttr: 'id' passed to background-applicat开发者_运维百科ion.in a word,i have passed made a wrong post action.can someone help me get out of this problem?


Use dijit/form/FilteringSelect not dijit/form/ComboBox.

You can enter any text into a ComboBox therefore it cannot return id which is the reason it returns text (or label or searchAttr). FilteringSelect allows only to chose one of options and therefore it can return id, which it does.

See it in action and experiment at jsFiddle: http://jsfiddle.net/phusick/QzQ38/

0

精彩评论

暂无评论...
验证码 换一张
取 消