我一直在关注这个教程http://tinyurl.com/327p325,这个教程一直很好,直到我无法让他的代码工作。我得到的列表使用静态项目,但我无法使用json项目。我试图通过我真正希望它来尝试调试错误的方式来简化它(如果有人可以告诉我如何查看将会很棒的Mojo日志)
在教程中,他必须使用yahoo服务将网站转换为json数据,而我想与之交互的网站已经生成了json数据,这就是我所拥有的
PageAssistant.prototype.setup = function() {
this.myListModel = { items : [] };
this.myListAttr = {
itemTemplate: "page/itemTemplate",
renderLimit: 20,
};
this.controller.setupWidget("MyList",this.myListAttr,this.myListModel);
this.controller.setupWidget("search_divSpinner", { spinnerSize : "large" }, { spinning: true } );
};
PageAssistant.prototype.activate = function(event) {
this.getData();
};
PageAssistant.prototype.getData = function () {
// the spinner doesn't show up at all
$("search_divScrim").show();
var url = "http://www.website.com/.json";
var request = new Ajax.Request(url, {
method: 'get',
asynchronous: true,
evalJSON: "false",
onSuccess: this.parseResult.bind(this),
on0: function (ajaxResponse) {
// connection failed, typically because the server is overloaded or has gone down since the page loaded
Mojo.Log.error("Connection failed");
},
onFailure: function(response) {
// Request failed (404, that sort of thing)
Mojo.Log.error("Request failed");
},
onException: function(request, ex) {
// An exception was thrown
Mojo.Log.error("Exception");
},
});
}
PageAssistant.prototype.parseResult = function (transport){
var newData = [];
var theStuff=transport.responseText;
try {
var json = theStuff.evalJSON();
}
catch(e) {
Mojo.Log.error(e);
}
// this is where I believe I am wrong
for (j=0;j < json.data.count;j++) {
var thread=json.data.children[j];
newData[j] = {
title: thread.data.author
};
}
this.myListModel["items"] = newData;
this.controller.modelChanged(this.myListModel , this);
$("search_divScrim").hide();
}
所以,我评论说我认为我错了,我只是想从这个json数据中获取标题
{ kind: Listing data: { children: [ { kind: food data: { author: Foodmaster hidden: false title: You should eat this } }, // then it repeats with the kind: and data
任何人都知道我哪里出错了?我想知道如何查看日志,因为我有日志事件,但无法弄清楚在哪里查看是否有任何一个被抛出。
答案 0 :(得分:1)
如果要查看Mojo日志,请打开终端(或您正在使用的任何命令行界面)并键入palm-log com.example.app
,将com.example.app替换为您在appinfo.json文件中定义的应用程序ID
您可能必须在此之前键入palm-log --system-log-level info
,以降低日志级别并查看每个日志(默认情况下,您只能看到由Mojo.Log.error生成的日志)