我想在dojox / mobile中为EdgeToEdgeStoreList使用自定义ListItem。 从这里开始:
https://dojotoolkit.org/reference-guide/1.9/dojox/mobile/templating-mobile-widgets.html
我创建了我的模板:
var template =
"<div>" +
" <div data-dojo-attach-point='labelNode'></div> ${size}" +
"</div>";
TemplatedListItem = declare(
[ListItem, TemplatedMixin], {
label: "My label",
size: "0",
templateString: template
}
);
然后我设立了我的商店:
store = new Memory({data: JSON.parse(json), idProperty: "Desc"});
list = registry.byId("list");
list.setStore(store)
但我不明白如何告诉EdgeToEdgeStoreList使用我的模板:
ul#list(data-dojo-type="dojox/mobile/EdgeToEdgeStoreList" data-dojo-props="itemMap: {Desc: 'label', Notes: 'size'}, select: 'single'")
我在CustomItem.js中创建了一个新包:
define([
"dojox/mobile/ListItem",
"dijit/_TemplatedMixin",
"dojo/_base/declare"
], function (ListItem, TemplatedMixin, declare) {
var template =
"<div>" +
" <div data-dojo-attach-point='labelNode'></div> ${size}" +
"</div>";
TemplatedListItem = declare("CustomItem",
[ListItem, TemplatedMixin], {
label: "My label",
size: "0",
templateString: template
}
);
});
然后我将它添加到dojoConfig:
dojoConfig = {
has: {
"dojo-firebug": true,
"dojo-debug-messages": true
},
packages: [{
name: "Alert",
location: "/javascripts",
main: "alert"
}, {
name: "CustomItem",
location: "/javascripts",
main: "CustomItem"
}],
parseOnLoad: false,
mblHideAddressBar: true,
async: true
};
需要像其他包一样:
require([
"dojox/mobile/parser",
"dojox/mobile/compat",
"dojox/mobile/EdgeToEdgeStoreList",
"dojox/mobile/SimpleDialog",
"CustomItem",
"dojo/domReady!"
], function (parser) {
parser.parse();
});
并设置itemRenderer属性:
ul#list(data-dojo-type="dojox/mobile/EdgeToEdgeStoreList" data-dojo-props="itemRenderer: CustomItem, itemMap: {Desc: 'label', Notes: 'size'}, select: 'single'")
但我得到了这个奇怪的错误:
TypeError:registry.byId(...)未定义