我使用Worklight for Android,iOS和&创建了一个多页面应用Windows Phone 8平台。在该应用程序中,我必须在某些页面中包含多个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模拟器/设备时,我没有收到警告“你好”。
非常感谢您解决问题的任何帮助。
答案 0 :(得分:1)
您需要等待第一个脚本加载第二个脚本。 getScript接受一个可以传递函数的第二个参数,或者你可以使用promises和带有done()函数的链接
<script>
$.getScript(path + "js/Page1.js").done(function(){
$.getScript(path + "js/sample.js");
});
</script>
我尝试了自己的工作
另请注意,在您的代码中使用问题时,请使用带大写“S”的Sample.js,并在评论中提到带有小写“s”的sample.js。我在文件名和代码中都使用了sample.js.
答案 1 :(得分:0)
在Windows Phone 8模拟器中测试您的示例项目(通过Visual Studio 12),在单击第1页按钮后,我收到一条提示“sample.js loaded”的警报。然后我点击了“显示提醒”按钮并收到一条提示“你好”的提示。
无法重现...
您的样本按原样在Worklight Studio 6.2.0.00-20140818-1919中正常工作(与您的相同版本和版本)。
也许你应该编辑你的问题并提供你为了重现这个问题而采取的全部步骤;也许你错过了一步。
我做了什么: