2017-02-23 6 views
1

dijit/form/DateTextBoxを拡張してカスタムウィジェットを作成し、次のエラーが表示される:エラー: 'GilCnPluginDojo.util.CustomDateTextBox'のコンストラクタを解決できない何が起こっているのか?何か間違って見ることはできません。これは私のコードです:dojoのエラー1.9カスタムウィジェットを拡張するdijit/form/DateTextBox

require(["dojo/ready", 
     "dojo/parser", 
     "dijit/form/DateTextBox", 
     "dojo/_base/declare", 
     "dijit/registry"], 
     function(ready, parser, DateTextBox, declare, registry) { 
     declare("GilCnPluginDojo.util.CustomDateTextBox", [DateTextBox], { 
     postCreate: function() { 
      this.inherited(arguments); 
      this.set('constraints', { 
       min: '01/01/1950', 
       max: new Date(), 
       datePattern: 'MM/dd/yyyy' 
      }); 
     } 
    }); 
}; 
+0

'return'はdeclare''の前に欠けています。 'return declare(" GilCnPluginDojo.util.CustomDateTextBox "...'。 – Himanshu

+0

あなたは 'CustomDateTextBox.js'のようなsignleファイルにこのコードを書いています –

+0

あなたに助けを借りていただきありがとうございます。しかし、 barbsanは私にこの問題を解決するのを助けた。 –

答えて

0

新しいオブジェクトを作成するには、宣言された型を変数に割り当てる必要があります。以下のスニペットを参照してください。 (私はunnecesaryモジュールを取り外したのだが、ドロップダウンのためにいくつかのCSSファイルをミスが、それはここでは重要ではありません。)

require(["dijit/form/DateTextBox", 
 
     "dojo/_base/declare"], 
 
     function(DateTextBox, declare) { 
 
    var CustomDateTextBox = declare("GilCnPluginDojo.util.CustomDateTextBox", [DateTextBox], { 
 
     postCreate: function() { 
 
      this.inherited(arguments); 
 
      this.set('constraints', { 
 
       min: '01/01/1950', 
 
       max: new Date(), 
 
       datePattern: 'MM/dd/yyyy' 
 
      }); 
 
     } 
 
    }); 
 
    
 
    new CustomDateTextBox().placeAt('result'); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.9.7/dojo/dojo.js"></script> 
 
<link href="https://ajax.googleapis.com/ajax/libs/dojo/1.9.7/dijit/themes/claro/claro.css" rel="stylesheet"/> 
 
<div id='result' class='claro'></div>

他のモジュールで、カスタムモジュールを使用するには、代わりに requiredefineを使用shoudと宣言されたクラスを返します。

//CustomDateTextBox.js 
define(["dijit/form/DateTextBox", "dojo/_base/declare"], 
function(DateTextBox, declare) { 
    return declare("GilCnPluginDojo.util.CustomDateTextBox", [DateTextBox], { 
    //some code 
    }); 
}); 

//MainModule.js 
require(["your/path/to/CustomDateTextBox"], 
function(CustomDateTextBox) { 
    var cdtb = new CustomDateTextBox(); 
}); 
+0

ありがとう@ barbsan! –

関連する問題