簡體   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