我想为我的dojox.mobile应用创建一个自定义ListItem小部件。它可以在我的HTML代码中使用它,但如果我尝试以编程方式使用它会抛出TypeError。
这是我的自定义ListItem的JS代码:
define([
"dojo/_base/declare",
"dojo/dom-construct",
"dojox/mobile/ListItem"], function(declare, domConstruct, ListItem){
var LabeledInputListItem = declare("myapp.LabeledInputListItem", ListItem, {
labelText: "",
placeholder: "",
value: "",
_setItemLabelAttr: function(val) {
this.labelText = val;
this.qDescSpan.innerHTML = val;
},
_setPlaceholderAttr: function(val) {
this.placeholder = val;
},
_setValueAttr: function(val) {
this.value = val;
},
startup: function(){
if(this._started){ return; }
},
constructor: function(params) {
this.placeholder = params.placeholder;
this.labelText = params.labelText;
this.valu = params.value;
},
buildRendering: function(){
this.inherited(arguments);
this.qDescDiv = domConstruct.create("div", {className: "tableItemDescription", id: "asd"}, this.labelNode, "before");
this.qDescSpan = domConstruct.create("span", null, this.qDescDiv, "first");
this.qInputDiv = domConstruct.create("div", {className: "tableItemInput"}, this.qDescDiv, "after");
this.qInputText = domConstruct.create("input", {className: "mblTextBox sessionTextbox", placeholder: this.placeholder, value: this.value}, this.qInputDiv, "first");
console.log(this.labelText, this.placeholder, this.value);
},
});
return LabeledInputListItem; });
我可以在我的html代码中使用这个自定义ListItem,如下所示:
<li data-dojo-type="myapp/LabeledInputListItem" data-dojo-props="itemLabel: 'asdasd', placeholder: 'placeholder', value: 'value'"></li>
但是,如果我尝试以编程方式创建自定义ListItem,则会导致以下错误:
TypeError: myapp.LabeledInputListItem is not a constructor
var childWidget = new myapp.LabeledInputListItem({placeholder: "placeholder"});
有人知道我错过了什么吗?
提前感谢您的帮助!
答案 0 :(得分:1)
我能想到的唯一(显而易见的)原因是你不需要模块吗? 顺便说一句,Dojo现在正朝着“无全局”的方式发展,所以最好不要给你的类提供一个明确的id,并使用AMD模块的值而不是全局的myapp.LabeledInputListItem。