Dojo 1.9 自定义小部件扩展 dijit/form/DateTextBox 时出错
Error in dojo 1.9 custom widget extending dijit/form/DateTextBox
开发扩展 dijit/form/DateTextBox 的自定义小部件并获得以下内容 error:Error:无法解析构造函数:'GilCnPluginDojo.util.CustomDateTextBox' 有人知道发生了什么吗?看不出有什么不妥。这是我的代码:
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'
});
}
});
};
您需要将声明的类型分配给变量以创建新对象。请参阅以下代码段。 (我已经删除了不必要的模块,它遗漏了一些 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>
要在其他模块中使用您的自定义模块,您应该使用 define
而不是 require
和 return 您声明的 class。
//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();
});
开发扩展 dijit/form/DateTextBox 的自定义小部件并获得以下内容 error:Error:无法解析构造函数:'GilCnPluginDojo.util.CustomDateTextBox' 有人知道发生了什么吗?看不出有什么不妥。这是我的代码:
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'
});
}
});
};
您需要将声明的类型分配给变量以创建新对象。请参阅以下代码段。 (我已经删除了不必要的模块,它遗漏了一些 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>
要在其他模块中使用您的自定义模块,您应该使用
define
而不是 require
和 return 您声明的 class。
//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();
});