2013-01-25 19 views
0

我建立我在其中創建一個組合框的表單中,我嘗試以填補一個JsonRestJsonRest在Dojo小部件,沒有方法查詢()

這是一個模板控件是我使用的代碼小工具:

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> 

但是當我嘗試使用組合框,我總是得到錯誤:

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

我一直在尋找一段時間,但還沒有找到解決方案。我試圖從模板中刪除商店,並直接在declare函數中的postCreate方法中調用查詢方法,但是這給了我相同的錯誤。

在此先感謝。 馬塞爾

解決方法:

問題是我如何傳遞函數的參數的順序確定。第一個參數是一個要包含的對象數組,第二個參數是一個包含變量列表的函數。

函數中變量的順序需要與傳遞數組中對象的順序相同。

因此widget的代碼現在看起來像:

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

回答

0

我不認爲你的worksector_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}); 
    } 
    }); 
}); 
+0

我做了一個簡單的測試,如果我做了'VAR worksector_store = ...'和'做postCreate:函數(){的console.log( worksector_store.query();}'在聲明我仍然得到相同的錯誤。 – MarEek