我正在通过这个函数在静态定义的dojox.mobile.RoundRectList小部件下动态构建一系列dojox.mobile.ListItem小部件……
function displayOpps(items) {
// Create the list container that will hold application names
var rrlOppsContainer = dijit.byId("rrlOpps");
// Add a new item to the list container for each element in the server respond
for (var i in items){
// Create and populate the list container with applications' names
var name = items[i].CustName + " - " + items[i].OppNbr;
var liOpps = new dojox.mobile.ListItem({
label: name,
moveTo: "sv3OppDetail"
});
// Add the newly created item to the list container
rrlOppsContainer.addChild(liOpps);
}}
当我在html文件中的onLoad()期间运行这段代码时,我在使用Chrome的开发工具时得到以下错误...
未捕获TypeError: Object #没有方法“byId”
我读过很多关于这个话题的文章,似乎很多人都有这个问题,但我发现的每一个都与其他一些技术(例如Spring MVC等)有关,我正在尝试通过一个基于dojox.mobile的应用程序来使用它。也就是说,我试图模仿其他人提出的一些解决方案,将它包含在我的html文件中,但它仍然不起作用……
<script type="text/javascript"
data-dojo-config="isDebug: true, async: true, parseOnLoad: true"
src="dojo/dojo.js">
dojo.require("dojox.mobile.RoundRectList")
</script>我做错了什么?
提前感谢您的时间和专业知识。
发布于 2012-07-09 15:57:24
如果您正在使用Dojo注册表,您可能只是忘记了需要“dijit/ 1.7+”模块。这是定义byId函数的地方。当您使用桌面小部件时,这是由其他基本模块间接加载的,但是对于dojox/mobile,您必须显式加载它(因为dojox/mobile默认情况下只加载非常少的模块,以最小化代码占用)。
根据您编写应用程序的方式,执行以下操作:
dojo.require("dijit.registry"); // legacy (pre-1.7) loader syntax
...
var rrlOppsContainer = dijit.byId("rrlOpps");
...或者这样:
require(["dijit/registry", ...], function(registry, ...){ // 1.7+ AMD loader syntax
...
var rrlOppsContainer = registry.byId("rrlOpps");
...
});另请注意,您的第二个代码示例尝试使用异步加载(async: true),而它使用的是传统加载程序语法。这是行不通的,要获得异步加载,你必须使用AMD语法。
https://stackoverflow.com/questions/11384812
复制相似问题