javascriptdojodstore

Get method in dojo dstore is not returning object even though data is present


I am trying to get the specific data by providing id to get method like this,

var person = [
              {id:1,name:"abc"},
              {id:2,name:"xyz"}
             ];
var detailsStore = new Memory([{data: person,idProperty:"id"}]);    

And getting value like this,

var person = detailsStore.get(1);
person.then(function(data){
var data1 = data.name;
},function(err){
console.log(err);
});

But the promise object returned by "detailsStore.get(1)" does not have any object hence the argument data in the callback function is undefined. Why it is not returning object even data is present?


Solution

  • This code works completely fine for me:

    require([
        'dstore/Memory'
    ], function (Memory) {
        var store = new Memory({ data: [
            { id: 1, name: 'abc' },
            { id: 2, name: 'xyz' }
        ] });
        store.get(1).then(function (data) {
            console.log(data.name);
        });
    });
    

    See fiddle.

    I suspect that if anything, you are trying to access data1 somewhere else that it is not defined? Perhaps see How do I return the response from an asynchronous call?