json - how to access javascript object from a function? -
let's have:
var test = {}; test.data1 = {     ...json objects here... };  test.data2 = {     ...json objects here... }; , on...  i access these json objects followed set of calls by:
this.scope.testdata = test['data1']; however, may data test getting larger wanted pass whatever data want function , processing like:
this.scope.setupdata = function(data) {     var fdata = test[data]; // line correct?      ...     ...     return fdata;  }; but it's not working. i'm getting :cannot set property "fdata" of undefined "[object object]" ... i'm new javascript, appreciated.
the problem scope inside this.scope.setupdata. access variables relate this.scope need use this again:
/**  * @ current scope, "this" refers object  * let's object named "parent"  *  * "this" contains property: "scope"  */ this.scope.setupdata = function(data) {     /**      * @ current scope, "this" refers "parent.scope"      *      * "this" contains "setupdata" , "testdata"      */     var fdata = this.testdata[data]; // line correct?      ...     ...     return fdata; }; 
Comments
Post a Comment