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

Proper way to handle nested data with can.Model

$
0
0
I am rather new with canjs and would like to know if the following is possible with can.Model.

I would like to be able to pass initial data to a view in a single request for performance reasons, but have subsequent operations on nested sets handled via different Model definitions (rest methods for CRUD operations in response to page changes).

Initial Request for product view may contain something like the following:

{
      "PartNumber": "blabla",
      "Description": "bla description",
      "Sales": [
            { "Year": "2013",  "Month": "1", "Total": "2000000" },
            { "Year": "2013",  "Month": "2", "Total": "2000000" },
            //etc....
      }],
      "CustomerPricing": [
            { "CustomerNumber": "1111111", "Level": "1",  "UofM": "EA", "Total": "100" },
            { "CustomerNumber": "1111111", "Level": "1",  "UofM": "BX", "Total": "2" },
      ],
      "Attributes": [...]
}

With this data I may have a selection for Sales years, on initial view load the data will contain the current year, but if the user then selects a different year, I would like to make a call to the server that only returns the sales for the selected year and have the Sales list updated with these values.  The same would be true for the other subcollections, if a user selects a different customer I could make a request for only that customers pricing without the need to return all of the data for other collections. 
Each sub collection would have a different URL for the update request than was used to load all of the initial data.

With my current understanding of how can.Model works I would need to break this up into separate can.Model instances and make separate calls to the server even on the initial view load.  I would like to make one initial call for all of the data that returns initial data, and then selectively update sub collections as needed.

I would be using live binding EJS templates with this.

Any help would be appreciated.

Viewing all articles
Browse latest Browse all 3491

Trending Articles