Dojo Widget中的JsonRest,没有方法查询()

时间:2013-01-25 13:52:00

标签: javascript combobox dojo

我正在构建一个模板化的小部件,我在其中创建一个带有ComboBox的表单,我尝试在其中填充JsonRest

这是我用于窗口小部件的代码:

define( [ 
  'dojo/_base/declare', 
  'dijit/_WidgetBase', 
  'dijit/_TemplatedMixin', 
  'dijit/_WidgetsInTemplateMixin', 
  'dojo/text!./templates/PanelDesigner.html', 
  'dijit/form/TextBox', 
  'dijit/form/Form', 
  'dojo/store/JsonRest', 
  'dijit/form/ComboBox' 
], 

  function(declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, template,   JsonRest) { 
    worksector_store = new JsonRest({ 
      target: '/worksectors' 
    }); 

  return declare('ppc.panel_designer.PanelDesigner',[_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { 
    templateString: template, 
    widgetsInTemplate: true 
  }); 
}); 

这是正在加载的模板:

<div id='${baseClass}' data-dojo-type='dijit/form/Form' data-dojo-id='${baseClass}'>
  <table>
    <tr>
      <td><label for:'name'>Name:</label></td>
      <td><input type='text' id='name' name='name' required='true' data-dojo-type='dijit/form/TextBox'/></td>
    </tr>
    <tr>
      <td><label for:'worksector'>Worksector:</label></td>
      <td><input id='worksector' name='worksector' data-dojo-type='dijit/form/ComboBox' data-dojo-props="store:worksector_store" /></td>
    </tr>
  </table>
</div>

但是当我尝试使用ComboBox时,我总是收到错误:

Uncaught TypeError: Object [Widget dijit.form.TextBox, dijit_form_TextBox_0] has no method 'query' 

我一直在寻找一段时间但尚未找到解决方案。我试图从模板中删除存储并直接在declare函数的postCreate方法中调用查询方法,但这给了我同样的错误。

提前致谢。 烫发

解决方案:

问题是我如何将函数的参数的顺序传递给define。第一个参数是要包含的对象数组,第二个参数是带有变量列表的函数。

函数中变量的顺序必须与传递数组中对象的顺序相同。

因此,小部件的代码现在看起来像:

define( [
  'dojo/_base/declare',
  'dijit/_WidgetBase',
  'dijit/_TemplatedMixin',
  'dijit/_WidgetsInTemplateMixin',
  'dojo/text!./templates/PanelDesigner.html',
  'dojo/store/JsonRest',
  'dojo/store/Memory',
  'dijit/form/ComboBox',
  'dijit/form/Form',
  'dijit/form/TextBox'
],
function(declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, template, JsonRest, Memory, ComboBox) {
  worksector_store = new JsonRest({
    target: '/worksectors'
  });

  return declare('ppc.panel_designer.PanelDesigner',[_WidgetBase, _TemplatedMixin,     _WidgetsInTemplateMixin], {
    templateString: template,
    widgetsInTemplate: true,
  });
});

1 个答案:

答案 0 :(得分:0)

我不认为您的worksector_store变量在模板中可见。我想你想要以声明的方式创建ComboBox:

define([..],function(..){
  var worksector_store = new JsonRest({});

  return declare('...',[deps],{
    buildRendering:function(){
      //do the other templated dom building
      this.inherited(arguments);
      this.comboBox = new CombBox({store:worksector_store});
    }
  });
});