0
我正在使用Worklight構建使用本地存儲的應用程序。我在common/js/myApp.js中聲明瞭函數createCollection()
。IBM Worklight 6.0 - 獲取「未捕獲類型錯誤無法調用方法'initCollection'未定義」
然而,當我在瀏覽器模擬器中運行它,在控制檯的JavaScript顯示:
Uncaught TypeError: Cannot call method 'initCollection' of undefined.
有什麼建議?
我的javascript:
function wlCommonInit(){
// Common initialization code goes here
}
// inizializzazione json
window.onload = createCollection;
var isOpen = true;
var menuboxw = $("#menubox").css("width");
$("#contentbox").css("left",menuboxw);
var headerh = $("#header").height();
$("#contentbox").css("top", headerh);
$("#menu_btn").click(function(){menu()});
// apertura/chiusura menu principale
function menu() {
if(isOpen){
$('#contentbox').animate({ left: -5 }, 1);
$("#menubox").css("visibility", "hidden");
isOpen = false;
}
else{
$('#contentbox').animate({ left: menuboxw }, 1);
$("#menubox").css("visibility", "visible");
isOpen = true;
}
}
// creazione collection 'canti' e 'categorie'
function createCollection(){
WL.Logger.debug("Called createCollection");
WL.SimpleDialog.show("Message", "createCollection called", [{text: "Ok"}]);
var collectionCanti = "canti";
var searchFieldsCanti = {titolo: "string", autore: "string", id_categoria: "string", testo: "string"};
var collectionCategorie = "categorie";
var searchFieldsCategorie = {titolo: "string", attiva: "number"};
var success = function(data){
logMessage("Collection created successfully " + data);
};
var failure = function(data){
logMessage("Collection doesn't created " + data);
};
var options = {onSuccess: success, onFailure: failure};
canti = WL.JSONStore.initCollection(collectionCanti, searchFieldsCanti, options);
categorie = WL.JSONStore.initCollection(collectionCategorie, searchFieldsCategorie, options);
}
它現在似乎工作,控制檯不再顯示錯誤,但對話框仍然無法正常工作。 JSONStore僅適用於iOS和Android環境,在瀏覽器中我無法顯示它是否可用,對不對?我還有一個問題:當調用wlCommonInit()時?我必須在其中放置哪些代碼部分? –
正如我寫的,DELETE「window.onload = createCollection;」和PASTE到wlCommonInit()函數「createCollection();」。我可以看到一個對話框。 wlCommonInit()在應用程序準備就緒時開啓。請閱讀IBM Worklight入門培訓材料。 –