Displaying the topics list on page load

Once the page load is completed, we need to fetch the topics from the server to be displayed on the profile page. So let's update the view with the necessary functions, as shown in the following code:

    var TopicListView = Backbone.View.extend({       el: $('#forum_member_topics'),       initialize: function () {         topicsList = new TopicCollection();         topicsList.bind("change", _.bind(this.getData, this));         this.getData();       }       getData: function () {         var obj = this;         topicsList.fetch({            success: function () {            obj.render();           }         });       },     }); 

Inside the initialize function, we bind an event named change for the topicsList collection, to call a function named getData. This event will get fired whenever we change the ...

Get Wordpress Web Application Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.