我正在尝试在我的worklight应用程序中使用两个自定义程序包并使用dojoConfig来使用它们。下面是我正在使用的脚本代码。问题是我收到错误“无法加载资源:服务器响应状态为404(未找到) - http://xxx.xx.xx.xxx:10080/js/controllers/HomeController.js“当我的应用程序尝试访问软件包时。我创建了js文件,其绝对路径为”StoreLocator_Proj / apps / StoreLocator_App / common / js / controllers / HomeController.js“。有谁可以请帮帮我这个错误的原因是什么?我在baseUrl做错了什么?
<script>
dojoConfig = {
baseUrl: "/js/",
tlmSiblingOfDojo: false,
parseOnLoad: true,
isDebug:false,
async:true,
simulateIpad:true,
mblAlwaysHideAddressBar: true,
packages: [
{ name: "controllers" , location: "controllers"},
{ name: "model" , location: "model"}
]
};
</script>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js"
data-dojo-config="async:true"></script>
答案 0 :(得分:1)
好吧,通常使用Dojo,包位置是相对于托管Dojo的位置。在这个例子中,它意味着它将在以下位置寻找您的模块:
http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/controllers/
http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/model/
因为您正在使用CDN。如果您想使用自定义程序包,那么您应该按照this article在Dojo上的建议在location
属性中定义主机名。
对于Worklight,它可能会有所不同,但我认为原因非常相似。因为您引用了CDN托管的Dojo,它将“错过”相对路径的一部分。为了解决这个问题,我建议使用本地版本的Dojo。例如:
<script type="text/javascript">
dojoConfig = {
isDebug: false,
async: true,
mblAlwaysHideAddressBar: true,
simulateIpad: true,
packages : [ {
name : "controller",
location : "/js/controller"
} ]
}
</script>
<script type="text/javascript" src="dojox/mobile/deviceTheme.js"></script>
<script type="text/javascript" src="dojo/dojo.js"></script>