Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : Models and Attributes

$
0
0
Here's the docs you were looking for:  http://canjs.com/docs/can.Map.attributes.html

Attributes is an optional plugin for can.Map.  

I don't recommend the approach you are trying to accomplish here.  Your "Post list" is really a separate object that *contains* a Post list. Instead, I recommend that you make a can.Model for Topic, which can then include a list of Post objects as a property. Using can.Map.Attributes would let you do this:

  1. can.Model.extend("Topic", {
  2.   findOne : "GET /api/v1/posts"
  3.   , attributes : {
  4.     posts : "Post.models"
  5.   }
  6. }, {});
What happens here is that when CanJS sets a "posts" property on any Topic object, it will run the source data (an array of plain JS object if you're returning from an XHR) through Post.models() which returns an array of Post objects, then set this array to be an observable property of the Topic object.

Viewing all articles
Browse latest Browse all 3491

Trending Articles