【发布时间】:2014-09-02 11:06:46
【问题描述】:
我使用适用于 Android、iOS 和 Windows Phone 8 平台的 Worklight 创建了一个多页应用程序。在该应用程序中,我必须在某些页面中包含多个 js 文件,这会在 Windows phone 8 环境中产生问题。
问题:如果我包含多个 js 文件,在 Windows phone 8 环境中只加载第一个 js 文件。
我使用 Worklight 多页应用程序创建了一个示例应用程序来演示该问题。
在Page1.html中,我包含了2个js文件。
<script>
$.getScript(path + "js/Page1.js");
$.getScript(path + "js/Sample.js");
</script>
<p>
Currently <b>Page1.html</b> page is loaded.
</p>
<input type="button" class="appButton" value="Show Alert" onclick="alertHello();" />
<input type="button" class="appButton" value="SimpleDialog from Page1" onclick="currentPage.buttonClick();" />
<input type="button" class="appButton" value="Insert Fragment" onclick="currentPage.insertFragment();" />
<div id="FragmentsDiv"></div>
<input type="button" class="appButton" value="BACK" onclick="currentPage.back();" />
sample.js 文件中的代码
$(document).ready(function(){
alert("sample.js loaded");
});
function alertHello()
{
alert("hello");
}
当我尝试在 Windows phone 8 环境中运行该应用程序时,只有 Page1.js 正在加载。
重现错误的步骤
点击“加载Page1.html”
点击“显示警报”
当我在 windows phone 8 模拟器/设备中尝试时,我没有收到警报“你好”。
我们将不胜感激任何解决问题的帮助。
【问题讨论】:
-
您是否查看了 IBM Worklight 提供的多页示例应用程序,该应用程序演示了应该如何为 Windows Phone 8 完成此操作?好好看看代码:ibm.com/developerworks/mobile/worklight/…
-
是的,我只使用了多页示例应用程序。从文档开始,windows phone 8 应用程序的路径不同,加载脚本时使用“路径”变量包含该值。我的问题是,第一个 js 文件正在加载,但第二个没有。
-
示例正在运行,因此如果您的示例无法正常运行 - 请提供可调试的完全运行的 Worklight 项目,否则提供的代码块不够。
-
示例中只有一个js文件。如果我们再包含一个,则不会加载第二个文件。
-
项目的文件结构是什么?该页面是位于 index.html 旁边还是位于 pages\ 文件夹内?如果您从 pages\ 文件夹(从中加载第一页)加载第二页,则路径不再是相同的路径,我认为对于第二页,您需要添加“..”才能返回进入 pages 文件夹以找到第二页。
标签: javascript windows-phone-8 ibm-mobilefirst