FilteringSelect in mvc

时间:2016-11-07 07:39:27

标签: javascript model-view-controller dojo

我想创建一个自动完成输入字段,以便用户开始输入,并在下拉列表中显示可能的值。我将从数据库中获取的数据。有动态商店的东西......我如何从控制器调用我的Methode?

我得到了以下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 个答案:

答案 0 :(得分:1)

FilteringSelect窗口小部件已经为您完成此操作,因此您需要做的就是在其上设置商店,它应该是开箱即用的!

由于您已经在HTML中设置了data-dojo-type属性,因此您无需在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>