开发者

JSON and WebOS simple example?

开发者 https://www.devze.com 2023-02-01 15:19 出处:网络
I have been following this tutorial http://tinyurl.com/327p325 which has bee开发者_JAVA百科n GREAT up until this point where I can\'t get his code to work.I get the list working with static items but

I have been following this tutorial http://tinyurl.com/327p325 which has bee开发者_JAVA百科n GREAT up until this point where I can't get his code to work. I get the list working with static items but I can't get it to work with the json items. I've tried to simplify it with what I really want it to do to try and debug what is wrong (also if someone could please tell me how to view the Mojo log that would be awesome)

In the tutorial he has to use the yahoo service to convert the site into json data, while the site I want to interact with already has json data generated so this is what I have


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(); }

So where I commented that I believe I am wrong I am just trying to get the title out of this json data

{
    kind: Listing
    data: {
        children: [
            {
                kind: food
                data: {
                    author: Foodmaster
                    hidden: false
                    title: You should eat this 
                }
            },
            // then it repeats with the kind: and data

Anyone see where I went wrong? I would like to know how to view the log as I have log events but can't figure out where to look to see if any of them are being thrown.


If you want to view Mojo logs open the terminal (or any command line interface you're using) and type palm-log com.example.app, replacing com.example.app with the app id you defined in your appinfo.json file.

You might have to type palm-log --system-log-level info before that, in order to lower the log level and see every log (by default you only see those generated by Mojo.Log.error)

0

精彩评论

暂无评论...
验证码 换一张
取 消