0

我正在构建一个模板化的小部件,在其中创建一个带有 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' 

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

提前致谢。马塞尔

解决方案:

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

函数中变量的顺序需要与传入数组中对象的顺序一致。

所以小部件的代码现在看起来像:

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,
  });
});
4

1 回答 1

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});
    }
  });
});
于 2013-01-25T13:59:53.643 回答