Posts

Showing posts with the label backbonejs

Partially rendering Handlerbars from Backbone view

Image
While working on a project I had this situation where I wanted to render a view partially after some ajax is done. In this post I will explain how to render HandlerBar views partially. For the purpose of demonstrate I will simulate delay using setTimeout() function instead of an ajax request. So for an example lets consider following setup 1. Template <script id="PersonTemplate" type="text/x-handlebars-template"> <div> {{firstName}} {{lastName}} <div> <div id="divPartial"> <a href="{{website}}">{{website}}</a> </div> </script> 2. Backbone Model var PersonModel = Backbone.Model.extend({ defaults: { firstName: 'Bharat', lastName: 'Patil', website: '' } }); 3. Backbone view using Handlerbars view var TestView = Backbone.View.extend({ //assign model view instance model: objPerson, //get the...

DataSync PhoneGap/Web applications using LocalStorage

Recently I have developed a PhoneGap application in which I wanted to synchronize data with server. In this post we will see a simple method to send data from PhoneGap application / Web application using LocalStorage as a queue. Conditions were like below: Store data in queue locally in LocalStorage Sync data with server if online when application comes online it should start syncing the data again if any upon successful sync remove from queue else try again synching one item at a time I have developed this solution using Backbone and Backbone LocalStorage plugin. Lets start understanding the solution. 1. Backbone Model var QueueModel = Backbone.Model.extend({ defaults:{ 'url': null, 'method': null //http method like GET, PUT, POST etc. } }); This model is nothing but representation of ajax settings that can be found here . 2. Backbone Collection used as a Queue which is using Backbone.LocalStorage plugin. You should use singleton p...