在dojo中动态填充ComboBox [英] Populating ComboBox dynamically in dojo

查看:227
本文介绍了在dojo中动态填充ComboBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在dojo中动态地填充一个ComboBox。我已经在html中声明了它,并且我试图在js中创建Memory store,然后使用我在js中创建的store值设置ComboBox的store属性。这是我的html和javascript文件。我在js中调用了一个获得json响应( )作为参数的函数,并且响应值即将到来(ResultData1,ResultData2,ResultData3 )。我测试了通过保持警戒框。但是当运行这个页面时,我得到 TypeError:内存不是构造函数错误。有人可以解释我做错了什么。

I am trying to populate a ComboBox dynamically in dojo. I have declared it in html and I am trying to created the Memory store in js and then setting the store attribute for the ComboBox with that value of store which I am creating in js. Here are my html and javascript files. I am calling a function in js which get a json response(item) as its argument and in that response values are coming(ResultData1,ResultData2,ResultData3) I have tested that by keeping alert boxes. But when running this page i am getting TypeError: Memory is not a constructor error. Can someone please explain me what i am doing wrong.

仅供参考:我在我的js文件中添加了所有必需的依赖列表。

FYI: I have added all the required dependency list in my js file.

HTML:

HTML:

<select data-dojo-type="dijit/form/ComboBox" data-dojo-attach-point="importDocumentTo" id="importDocumentTo" name="importDocumentTo">

JavaScript:

JavaScript:

_onPopulate : function(item) {
                 alert('_onPopulate:');            
                 var combo = dijit.byId('importDocumentTo');
                 alert('combo' + combo)

                 var stateStore=new Memory({
                       data: [
                              {name:item["ResultData1"], id:"data1"},
                              {name:item["ResultData2"], id:"data2"},
                              {name:item["ResultData3"], id:"data3"}
                              ]      
                 });

                 alert('stateStore:' + stateStore);

          var result=domAttr.set("importDocumentTo","store",stateStore);


推荐答案

使用DOM API更新窗口小部件上的商店不会工作。而不是使用 domAttr.set 来设置商店,您应该引用该小部件本身并调用 set('store',...)

Using a DOM API to update the store on a widget is not going to work. Instead of using domAttr.set to set the store, you should be referencing the widget itself and calling set('store', ...) on the widget.

此外,应该不需要静态 id 该模板中的小部件,因为您已经为其分配了一个附加点。为它分配一个静态的 id 使得无法一次创建多个小部件实例,因为静态ID会在实例间冲突。

Moreover, there should be no need for a static id on the widget in your template, since you are already assigning it an attach point. Assigning it a static id makes it impossible to create more than one instance of the widget at a time, because the static ID would conflict between instances.

您应该能够通过以下更改解决您的问题:

You should be able to solve your problem with the following changes:


  1. 删除静态 id =... from

  2. 替换 var combo = dijit.byId('importDocumentTo' ) with var combo = this.importDocumentTo (引用附加点而不是ID)

  3. domAttr.set(importDocumentTo,...)替换为 combo.set('store',stateStore)

  1. Remove the static id="..." from the element in the template
  2. Replace var combo = dijit.byId('importDocumentTo') with var combo = this.importDocumentTo (to reference the attach point rather than the ID)
  3. Replace domAttr.set("importDocumentTo", ...) with combo.set('store', stateStore)

这篇关于在dojo中动态填充ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆