2011-08-23 3 views
3

마크 업 선언 된 dijit.form.Select 위젯에 대한 옵션을 JSON 선언을 통해 선언하려고합니다. API 문서에서 읽은 바를 토대로하면 setStore()를 사용하여 새 저장소를 전달한 다음 업데이트해야하지만 전체 저장소가있는 빈 Select 위젯 외에 유용한 결과가 생성되지 않은 것으로 보입니다. 잘못된 메서드를 사용하고 있거나 이러한 옵션을 선언하는 다른 방법이있는 경우 내 개체에서 누락 된 선언이 있는지 궁금합니다. 난 당신이 상점을 놓치 초기화하는 생각dijit.form.select의 값을 프로그램 적으로 선언하기

<!DOCTYPE HTML> 
<html dir="ltr"> 

    <head> 
     <style type="text/css"> 
      body, html { font-family:helvetica,arial,sans-serif; font-size:90%; } 
     </style> 
     <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/dojo.xd.js" 
     djConfig="parseOnLoad: true"> 
     </script> 
     <script> 
      dojo.require("dijit.form.Select"); 
      dojo.require("dojo.data.ItemFileReadStore"); 
      dojo.require("dojo.data.ItemFileWriteStore"); 
     </script> 
     <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css" /> 
    </head> 

    <body class=" claro "> 

     <div class="option" id="option" dojoType="dijit.form.Select"></div> 

     <script type="text/javascript"> 
      dojo.addOnLoad(function() { 
       if (document.pub) { 
        document.pub(); 
       } 

       var selectOptions = { 
        name:'selection', 
        identifier: 'label', 
        options: [{ 
         label: 'this', 
         value: '01' 
        }, 
        { 
         label: 'that', 
         value: '02' 
        }, 
        { 
         label: 'the other', 
         value: '03' 
        }, 
        { 
         label: 'banana', 
         value: '04', 
        }, 
        ]}; 

        var aStore = dojo.data.ItemFileReadStore({data: selectOptions}); 
        dijit.byId("option").setStore(aStore, 01); 
        dijit.byId("option").startup(); 

      }); 
     </script> 
    </body> 

</html> 

답변

7

@missingno가 언급했듯이이 저장소는 과도한 사용입니다. 당신은 그것이 될 것입니다 귀하의 예제에서

dijit.form.select.addOption(/*array of options*/). 

를 사용할 수 있습니다

var listOfOptions = [{ 
    label: 'this', 
    value: '01' 
    }, 
    { 
    label: 'that', 
    value: '02' 
    }, 
    { 
    label: 'the other', 
    value: '03' 
    }, 
    { 
    label: 'banana', 
    value: '04', 
    }, 
    ]; 
dijit.byId("option").addOption(listOfOptions); 
+0

이 내가 사용하는 결국 궁극적 것입니다. 감사. –

2

:

내가 사용하고 테스트 마크 업

은 아래에 인쇄됩니다. 옵션은 일반 select를 초기화하는 데 사용되는 옵션과 비슷합니다. 당신은 당신이 이것에 대한 저장소를 사용할 필요가 확신,

http://dojotoolkit.org/reference-guide/dojo/data/ItemFileReadStore.html

var store_options = { 
    identifier: 'label', 
    label: 'label', 
    items: [ 
     {label: 'this', value:'01'}, 
     //... 
    ] 
} 

var store = dojo.data.ItemFileWriteStore({data: store_options}) 

OTOH : 같은 일을하려고? 특정 저장소 기능 (예 : 알림)을 사용하려는 경우가 아니라 프로그래밍 방식으로 선택 항목을 만들 때 데이터를 직접 전달할 수 있습니다. http://dojotoolkit.org/reference-guide/dijit/form/Select.html

관련 문제