How to call a method inside a javascript object

后端 未结 5 1463
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-08 17:23

I\'m just learning about how to best organize my javascript code, and I had a question regarding this small piece of code I wrote:

var reportsControllerIndex = {         


        
5条回答
  •  情歌与酒
    2021-02-08 18:14

    You need to use a variable reference to this outside the getJSON function. getJSON sets the context of the callback within jquery.

    Like this:

    var self = this;
    $.getJSON('/reports.json', function(data) {
        self.plotMapPoints(data);         
    });
    

提交回复
热议问题