Search code examples
firebasebackbone.jsfirebase-realtime-databasebackbone.js-collectionsbackbonefire

how to display fetch data form firebase in backbone?


I am learning backbone.js. I am using firebase for API. I can't able to display data. Can anyone help me please?

I follow instruction mention on https://github.com/firebase/backbonefire.

var realtimeList = new RealtimeList();
realtimeList.on('sync', function(collection) {
  console.log('collection is loaded ', collection);
//  todoView.render();
});

Collection is object.

DEMO


Solution

  • Your view element is not part of DOM. You need to add it to DOM. I've used el property to do so for the sake of demo.

    Also you need to stringify the JavaScript object returned by toJSON() to display in DOM.

    Updated demo.

    Your API is returning empty collection at the moment so I've used the todoItem model created locally for demo. But it isn't part of the Firebase collection. You need to pass the collection to view and render the models inside it in order to view realtime data.