IBM Worklight 6.0 - 获取“未捕获类型错误无法调用方法'initCollection'未定义”

时间:2013-10-04 10:58:13

标签: ibm-mobilefirst jsonstore

我正在使用Worklight构建一个使用本地存储的应用程序。我在common / js / myApp.js中声明了一个函数createCollection()

但是,当我在浏览器模拟器上运行它时,控制台JavaScript会显示:

  

未捕获的TypeError:无法调用未定义的方法'initCollection'。

有什么建议吗?

我的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);

}

1 个答案:

答案 0 :(得分:1)

执行以下操作:

  1. 删除window.onload = createCollection;
  2. createCollection();
  3. 中添加wlCommonInit()

    顺便说一句,logMessage会产生错误。应该更改为WL.Logger.debug(您已经在代码中使用了......)。


    请查看IBM Worklight Getting Started training material。没有跳过。