2013-02-15 50 views
0

我正在使用dojo並希望從dataStore填充一個dijit.form.select小部件(此工作原理)。 每當我在select-widget中做出選擇時,我應該讀取dataStore中的其他字段,然後將其顯示在頁面上的文本框中。dojo dijit.form.select:從dataStore獲取數據?

不幸的是我不知道如何從我的數據存儲中讀取其他字段。這裏是我的代碼:如果您滾動一路下跌

http://jsbin.com/xxx

重要的事情發生。

這裏是JavaScript對象,然後將其讀入的數據存儲:

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> 

對於前當我選擇 「名」: 「信息」, 「subject_main」: 「789」, 「subject_1」:「sub1」,「subject_2」:「sub2」

消息應顯示在我的dijit中。

編輯:盧西恩幫了我很多!這是我對這個問題的最終解決方案:

<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" 

數據道場-配置= 「isDebug:真,異步:真,parseOnLoad: 真正」>

Beladeauftrag 地址

Naviga灰>

<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」} ]};

 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> 

回答

1

你正在做一個有趣的方式!爲什麼使用span元素定義商店?

看看這篇文章:

Dojo how to get JSON attribute from dojo.data.ItemFileReadStore

UPDATE:

那你應該怎麼做:

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

盧西恩

+0

thx爲tipp!我找不到關於如何以正確的方式創建數據存儲的文檔,所以我只是從stackoverflow複製粘貼。 現在我正在生成腳本標記中的數據存儲和以下代碼: var store1 = new dojo.data.ItemFileReadStore({data:jsonData}); 仍然需要我的主要問題的解決方案:) – RCK69 2013-02-15 12:56:58

+1

你可以做一個新的jsfiddle嗎?我看到你使用getElementById來訪問輸入元素。這些元素是dijit小部件!你不應該那樣訪問它們!使用myElement = dijit.byId(「idHierRein」);相反!如果你想設置它們的值,請執行myElement.attr(「value」,「wertHierRein」); – 2013-02-15 13:07:52

+1

在生產模式下數據來自您的表單? – 2013-02-15 13:16:19