Quantcast
Viewing all articles
Browse latest Browse all 3491

Models and Attributes

In my 'new Post.List({})' call I want my JSON response to have extra attributes including the 'posts' array of collections. So I would like to have:

  1. {
  2. title: 'This is the title for topic',
  3. created_at: '30 mins ago',
  4. posts: [{
  5.       id: 1,
  6.       title: 'post 1',
  7.       body: 'message blah blah'
  8. },{
  9.       id: 2,
  10.       title: 'post 2',
  11.       body: 'message blah blah'
  12. }]
  13. }
I have read somewhere in the documentation about 'attributes' for models but I can't find it again. Below is my model, at the moment its very basic. By doing this how would I refer to the posts array from the view via this new JSON response?

  1. can.Model.extend 'Post',
  2. findAll: 'GET /api/v1/posts'
  3. create:  'POST /api/v1/posts'
  4. , {}

  5. Post.List = Post.List.extend()



Viewing all articles
Browse latest Browse all 3491

Trending Articles