I have been following this tutorial http://tinyurl.com/327p325 which has been 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.