2016-11-07 101 views
0

我想創建一個自動填充輸入字段,以便用戶開始輸入,並在下拉菜單中顯示可能的值。我將從數據庫中獲得的數據。動態商店的東西...我怎麼能從控制器調用我的Methode?在mvc中篩選選擇

我有以下JS功能:

searchNames:function() 
    { 
     var jsonStore = new JsonRest({ 
      url: config.rootContext + '/link/to/controllerMethod' 
     }); 
     var memoryStore = new Memory(); 
     var myStore = new Cache(jsonStore, memoryStore); 


     var fs = new FilteringSelect({ 
      id: dijit.byId("serviceSelect"), 
      store : memoryStore, 
     }); 
     debugger; 
     when(myStore.query({id:""})), 
      function (items, request) 
      { 
       var val = ""; 
       if(items.length>0) val = items[0].id; 
       fs.set('value', val); 
      } 
    }, 

而我的小部件包含:

<td><select data-dojo-type="dijit/form/FilteringSelect" id="serviceSelect" data-dojo-attach-event="onClick:searchNames"></select></td> 

感謝輸入。

回答

1

FilteringSelect小部件已經爲你做了這個,所以你所需要做的就是設置存儲,它應該開箱即用!

既然你已經有了屬性在HTML設置,你不需要在你的JS代碼創建另一個FilteringSelect

var jsonStore = new JsonRest({ 
    url: config.rootContext + '/link/to/controllerMethod' 
}); 
var memoryStore = new Memory(); 
var myStore = new Cache(jsonStore, memoryStore); 

var selectWidget = registry.byId('serviceSelect'); // registry refers to dijit/registry 
selectWidget.set('store', myStore); 

的HTML應該是這樣的:

<td><select data-dojo-type="dijit/form/FilteringSelect" id="serviceSelect"></select></td> 
+0

感謝ysou。我是否必須將這段代碼放在構造函數中(或者其他類似的東西),還是需要添加一些onChange方法? – Herrminator

+1

這段代碼應該放在你的頁面的「controller」中 - 如果它是另一個父窗口部件,你應該放在「postCreate」中,或者它只是一些執行onDocumentReady的代碼,你也可以放在那裏 – Corina