简体   繁体   English

dojo dijit.form.select:从dataStore中获取数据?

[英]dojo dijit.form.select : getting data out of the dataStore?

I am using dojo and want to populate a dijit.form.select widget from a dataStore (this works). 我正在使用dojo,并想从dataStore中填充dijit.form.select小部件(这可行)。 Whenever I make a selection in the select-widget, other fields from my dataStore should be read and then be displayed in the textBoxes on the page. 每当我在select-widget中进行选择时,都应该读取dataStore中的其他字段,然后将其显示在页面的文本框中。

Unfortunately I dont know how to read the other fields from my data store. 不幸的是,我不知道如何从我的数据存储中读取其他字段。 Here is my code: 这是我的代码:

http://jsbin.com/xxx http://jsbin.com/xxx

The important stuff happens if you scroll all the way down. 如果您一直向下滚动,则会发生重要的事情。

Here is the javascript Object which is then read into the dataStore: 这是JavaScript对象,然后将其读入dataStore:

  var jsonData = {"identifier":"name",
                  "label": "subject_main",
                  "items": [
    {"name":"departure",   "subject_main":"123",  "subject_1":"sub1", "subject_2":"sub2"},
    {"name":"direct",       "subject_main":"456",  "subject_1":"sub1", "subject_2":"sub2"},
    {"name":"Messaging",           "subject_main":"789",  "subject_1":"sub1", "subject_2":"sub2"},
    {"name":"exchange",      "subject_main":"1011", "subject_1":"sub1", "subject_2":"sub2"},
    {"name":"Zilo",                "subject_main":"1213", "subject_1":"sub1", "subject_2":"sub2"},
    {"name":"Stub_implementation",            "subject_main":"1415", "subject_1":"sub1", "subject_2":"sub2"},
    {"name":"Standard_implementation",  "subject_main":"1617", "subject_1":"sub1", "subject_2":"sub2"}
                        ]};
  </script>

For ex when I select "name":"Messaging", "subject_main":"789", "subject_1":"sub1", "subject_2":"sub2" 例如,当我选择“ name”:“ Messaging”,“ subject_main”:“ 789”,“ subject_1”:“ sub1”,“ subject_2”:“ sub2”

Messaging should be displayed in my dijit. 消息应该显示在我的dijit中。

EDIT: Lucian helped me a lot! 编辑:卢西安(Lucian)帮助了我很多! Here is my final solution for the problem: 这是我对这个问题的最终解决方案:

 <title>Hello Dijit!</title> <!-- load Dojo --> <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.8.1/dijit/themes/claro/claro.css"> <script src="//ajax.googleapis.com/ajax/libs/dojo/1.8.1/dojo/dojo.js" 

data-dojo-config="isDebug: true, async: true, parseOnLoad: true"> data-dojo-config =“ isDebug:true,async:true,parseOnLoad:true”>

Beladeauftrag Adresse Beladeauftrag地址

Navigation> 导航>

 <label for="load">Laden am</label><br> <input type="text" value="" data-dojo-type="dijit/form/TextBox" data-dojo-props="trim:true, propercase:true" id="load" /><br> <label for="from">von</label><br> <input type="text" value="" data-dojo-type="dijit/form/TextBox" data-dojo-props="trim:true, propercase:true" id="from" /><br> <label for="till">bis</label><br> <input type="text" value="" data-dojo-type="dijit/form/TextBox" data-dojo-props="trim:true, propercase:true" id="till" /><br> <script> // load requirements for declarative widgets in page content require(["dijit/form/Button", "dojo/parser", "dijit/form/TextBox", "dojo/domReady!", "dojo/data/ItemFileReadStore"]); </script> <br> <br> <h2>WF auswählen</h2> <div id="stateSelect"></div> <script> require(["dijit/form/Select", "dojo/store/Memory", "dojo/json", "dijit/registry" , "dojo/ready"], function(Select, Memory, json, registry, ready) { ready(function(){ var jsonData = {"identifier":"name", "label": "subject_main", "items": [ {"name":"Auftrag 1", "subject_main":"123", "subject_1":"sub1", "subject_2":"sub2"}, {"name":"Auftrag 2", "subject_main":"456", 

"subject_1":"sub1", "subject_2":"sub2"} ]}; “ subject_1”:“ sub1”,“ subject_2”:“ sub2”}]};

  var store1 = new dojo.data.ItemFileReadStore({ data: jsonData }); // code useless - nut dijit.form.select fanishes without it (??) // create Select widget, populating its options from the store var select = new Select({ name: "WorflowSelect", store: store1, style: "width: 200px;", labelAttr: "name", maxHeight: -1, // tells _HasDropDown to fit menu within viewport myAttr1: "this.get(name)", myAttr2: "subject_2", onChange: function(value){ // get references to widgets adressW=dijit.byId("adress"); loadW=dijit.byId("load"); fromW=dijit.byId("from"); tillW=dijit.byId("till"); adressW.attr("value", "subject_main from js-object"); loadW.attr("value", "subject_1 from js-object"); fromW.attr("value", "subject_2 from js-object"); tillW.attr("value", store1._getItemByIdentity("Auftrag 1").subject_main); } }, "stateSelect"); select.startup(); }); }); </script> </body> </html> 

You are doing it a funny way ! 你这样做很有趣! Why do you define the store using a span Element ? 为什么要使用span元素定义商店?

Take a look at this post: 看一下这篇文章:

Dojo how to get JSON attribute from dojo.data.ItemFileReadStore Dojo如何从dojo.data.ItemFileReadStore获取JSON属性

UPDATE: 更新:

Thats how you should do it: 那就是你应该怎么做:

http://jsbin.com/osiniv/3/edit http://jsbin.com/osiniv/3/edit

Lucian 露西安

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM