Search code examples
javascriptjqueryjsonlawnchair

Getting LawnChair JSON Obj after storing


I'm a little confused on how to retrieve my JSON object from a different page.

Page 1 Snippet [Storing]:

$.getJSON(serviceURL + 'getTaskDetails.php?id='+id, storeTasks); //[JSON Format of getTaskDetails][1]

function storeTasks(data) {

  var tasks = Lawnchair({name:'tasks'},function(e){});

  var taskList = data.tasks; //tasks is JSON array name

  tasks.save({key:"task",value:taskList});

  tasks.get("task",function(obj){
    console.info(obj);
  });
}

The .get returns my object (output from Firebug):

key "task"

value   Object { name="Level fireplace mantle", start_date="2012-01-22 00:00:00", created_by="[email protected]"}

How do I reference this from another page?

Lawnchair(function(){
        this.get('task', function(obj) {
        console.info(obj);
        })
})

The above returns the object, but won't let me reference individual elements (ex: I've tried obj.name or obj.tasks.name or obj.Object.name all result in "undefined") Any suggestions on what I'm doing wrong? Maybe I'm storing it incorrectly to begin with?


Solution

  • You're very close! Here's your brief answer: console.log(obj['value']);

    For those watching from home:

    Page one:

    Lawnchair(function(){
        this.save({key:"task",value:taskList});
    });
    

    Page two:

    Lawnchair(function(){
        this.get('task', function(obj) {
            if(obj) {
                console.log("found task");
                console.log(obj['value']);
            } else {
                console.log("task not found");
            }
        })
    });