How to call a method inside a javascript object

后端 未结 5 578
北荒
北荒 2021-02-08 17:30

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:06

    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);         
    });
    

提交回复
热议问题