0

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

Marmik Desai
  • 104
  • 11

1 Answers1

1

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.

T J
  • 42,762
  • 13
  • 83
  • 138
  • Hi @TJ Thanks for replay. can you please check https://jsfiddle.net/3uokuqzy/2/ this. I am getting error – Marmik Desai Feb 21 '17 at 11:34
  • 1
    @MarmikDesai Read the updated answer and try to do what is suggested. Also read the documentation and understand what you're doing. There is too many errors in your code. `model: todoItem` model prop is not supposed to be an instance of modal in backbone. I don't expect it to be different in firebase collection. – T J Feb 21 '17 at 11:41