rest - Backbone RESTful JSON schema -


if want present following data backbone.js collection, should json create like?:

id: 1 fname: "john" surname: "lennon" email: "john@beatles.com" age: 22  id: 2 fname: "paul" surname: "mccartney" email: "paul@beatles.com" age: 22  id: 3 fname: "george" surname: "harrison" email: "george@beatles.com" age: 20  id: 4 fname: "ringo" surname: "starr" email: "ringo@beatles.com" age: 24 

i have been exporting follows:

[{     "id":1,     "fname":"john",     "surname":"lennon",     "email":"john@beatles.com",     "age":22 },{     "id":2,     "fname":"paul",     "surname":"mccartney",     "email":"paul@beatles.com",     "age":22 },{     "id":3,     "fname":"george",     "surname":"harrison",     "email":"george@beatles.com",     "age":20 },{     "id":4,     "fname":"ringo",     "surname":"starr",     "email":"ringo@beatles.com",     "age":24 }] 

when presented json above, collection seems contain final beatle (ringo).


this view:

var app = app || {};  app.beatleview = backbone.view.extend({          el: '#page',          template: handlebars.gettemplate( 'account_statement' ),          initialize: function() {                 console.info('init:',this.collection);                 this.render();                 this.listento(this.collection, 'add', this.render);                 this.listento(this.collection, 'reset', this.render);                 this.collection.fetch();         },          // render library rendering each book in collection         render: function() {                 var data = this.collection.tojson();         console.log('col', this.collection );  // added                 this.$el.html( this.template( {beatles: data} ));                 return this;         } }); 

this collection

var app = app || {};  app.beatlescollection = backbone.collection.extend({         model: app.beatle,         url: 'http://localhost/path/to/beatles',          initialize: function() {                 console.log('init collection');         } }); 

this model

var app = app || {};  // create model represent single transaction on statement app.transaction = backbone.model.extend({}); 

this console.log('col', this.collection ); in view's render method show:

col child {length: 1, models: array[1], _byid: object, _listenerid: "l2", _events: object…} _byid: object _events: object _listenerid: "l2" length: 1 models: array[1] 0: child _changing: false _events: object _pending: false _previousattributes: object attributes: object amount: 205.99 currency: "usd" date: "2013-05-13" id: 13 vendor: "reebok outlet" __proto__: object changed: object cid: "c3" collection: child id: 13 __proto__: surrogate length: 1 __proto__: array[0] __proto__: surrogate 

my handlebars template looks this:

<h1>your statement</h1> <table border="1">     <thead>         <th>name</th>         <th>email</th>         <th>age</th>     </thead>     <tbody>     {{#each beatle}}         <tr>             <td>{{this.fname}} {{this.surname}}</td>             <td>{{this.email}}</td>             <td>{{this.age}}</td>         </tr>     {{/each}}     </tbody> </table> 

it looks json posted above correct.

the problem json posted pseudo-code , json outputting backend system wrong -- of ids in output same number (copy/paste problem).

for looking create backbone / handlebars app, code above seems starting point.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -