繁体   English   中英

Worklight 6.2:无法在Windows Phone 8环境中添加多个js文件

[英]Worklight 6.2 : Unable to add multiple js files in windows phone 8 environment

我使用Worklight为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。

重现错误的步骤

  1. 点击“加载Page1.html”

  2. 点击“显示提醒”

我在Windows Phone 8模拟器/设备中尝试时未收到警报“你好”。

任何解决问题的帮助将不胜感激。

您需要等待第一个脚本完成才能加载第二个脚本。 getScript需要第二个参数,您可以传递一个函数,也可以使用诸如promise的链接,并与done()函数链接

<script>
  $.getScript(path + "js/Page1.js").done(function(){
    $.getScript(path + "js/sample.js");
  });
</script>

我尝试了自己,这有效 在此处输入图片说明

还要注意,在代码中的问题中,请使用大写字母“ S”的Sample.js,在注释中提到小写字母“ s”的sample.js。 我在文件名和代码中都使用了sample.js。

在Windows Phone 8模拟器中(通过Visual Studio 12)测试示例项目,单击“页面1”按钮后,我收到一条警告,提示“已加载sample.js”。 然后,我单击“显示警报”按钮,并收到一条警告消息,说“你好”。

无法复制...
您的样例可以在Worklight Studio 6.2.0.00-20140818-1919(与您相同的版本和版本)中正常工作。

也许您应该编辑您的问题并提供您已采取的全部步骤以重现此问题; 也许您错过了一步。

我所做的:

  1. 导入项目
  2. 右键单击Windows Phone 8文件夹>“运行方式”>“ Visual Studio项目”
  3. VS打开>单击“播放”按钮
  4. WP8仿真器打开>完成以上操作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM