Javascript Dojo小部件中的JsonRest,无方法查询()
我正在构建一个模板化的小部件,在其中我创建了一个表单,其中包含一个组合框,我试图用JsonRest填充该组合框 这是我用于小部件的代码:Javascript Dojo小部件中的JsonRest,无方法查询(),javascript,combobox,dojo,Javascript,Combobox,Dojo,我正在构建一个模板化的小部件,在其中我创建了一个表单,其中包含一个组合框,我试图用JsonRest填充该组合框 这是我用于小部件的代码: define( [ 'dojo/_base/declare', 'dijit/_WidgetBase', 'dijit/_TemplatedMixin', 'dijit/_WidgetsInTemplateMixin', 'dojo/text!./templates/PanelDesigner.html', 'dijit/f
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>
我已经搜索了一段时间,但还没有找到解决方案。我试图从模板中删除存储,并在declare函数中的postCreate方法中直接调用query方法,但这给了我相同的错误
提前谢谢。
马塞尔
解决方案:
问题是我如何调整传递给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,
});
});
我认为您的
worksector\u store
变量在模板中不可见。我认为您只需要以声明方式创建组合框:
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});
}
});
});
我做了一个快速测试,如果我在声明中执行
var worksector_store=…
和postCreate:function(){console.log(worksector_store.query();}
,我仍然会得到相同的错误。
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});
}
});
});