简体   繁体   English

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

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

I created a multipage app using Worklight for Android,iOS & Windows Phone 8 platforms. 我使用Worklight为Android,iOS和Windows Phone 8平台创建了一个多页应用程序。 In that app, I have to include multiple js files in some pages, which is creating issues in the Windows phone 8 environment. 在该应用中,我必须在某些页面中包含多个js文件,这在Windows Phone 8环境中造成了问题。

Issue : If I include multiple js files, only first js file is loading in Windows phone 8 environment. 问题:如果我包含多个js文件,则在Windows Phone 8环境中仅加载第一个js文件。

I created a sample application using Worklight multi-page app to demonstrate the issue. 我使用Worklight多页应用程序创建了一个示例应用程序来演示该问题。

In the Page1.html, I included 2 js files. 在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();" />

Code in sample.js file sample.js文件中的代码

$(document).ready(function(){
    alert("sample.js loaded");
});

function alertHello()
{
    alert("hello");
}

When i tried to run the app in Windows phone 8 environment, Only the Page1.js is loading. 当我尝试在Windows Phone 8环境中运行该应用程序时,仅正在加载Page1.js。

STEPS TO REPRODUCE ERROR 重现错误的步骤

  1. Click "Load Page1.html" 点击“加载Page1.html”

  2. Click "Show Alert" 点击“显示提醒”

I am not getting the alert "hello" when I tried in windows phone 8 emulator/device. 我在Windows Phone 8模拟器/设备中尝试时未收到警报“你好”。

Any help in solving the issue will be much appreciated. 任何解决问题的帮助将不胜感激。

You need to wait for the first script to be done to load the second script. 您需要等待第一个脚本完成才能加载第二个脚本。 getScript takes a second parameter you can pass a function, or you can use promises like and chain with a done() function getScript需要第二个参数,您可以传递一个函数,也可以使用诸如promise的链接,并与done()函数链接

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

I tried my self and it works 我尝试了自己,这有效 在此处输入图片说明

also notice that in your question in your code use use Sample.js with upper case "S" and in your comments you mentioned sample.js with lower case "s". 还要注意,在代码中的问题中,请使用大写字母“ S”的Sample.js,在注释中提到小写字母“ s”的sample.js。 I use sample.js in both file name and code. 我在文件名和代码中都使用了sample.js。

Testing your sample project in windows Phone 8 emulator (via Visual Studio 12), after clicking the Page 1 button I got an alert saying "sample.js loaded". 在Windows Phone 8模拟器中(通过Visual Studio 12)测试示例项目,单击“页面1”按钮后,我收到一条警告,提示“已加载sample.js”。 I then clicked on the Show Alert button and got an alert saying "hello". 然后,我单击“显示警报”按钮,并收到一条警告消息,说“你好”。

Cannot reproduce... 无法复制...
Your sample as-is is working just fine in Worklight Studio 6.2.0.00-20140818-1919 (same version and build as yours). 您的样例可以在Worklight Studio 6.2.0.00-20140818-1919(与您相同的版本和版本)中正常工作。

Maybe you should edit your question and provide the full steps you have taken in order to reproduce this; 也许您应该编辑您的问题并提供您已采取的全部步骤以重现此问题; maybe you are missing a step. 也许您错过了一步。

What I've done: 我所做的:

  1. Imported the project 导入项目
  2. Right-clicked on the Windows Phone 8 folder > Run As > Visual Studio project 右键单击Windows Phone 8文件夹>“运行方式”>“ Visual Studio项目”
  3. VS opens > click on the "play" button VS打开>单击“播放”按钮
  4. WP8 emulator opens > did the above WP8仿真器打开>完成以上操作

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

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