Note that there are some explanatory texts on larger screens.

plurals
  1. PObackbone.js populate large nested model from asp.net mvc viewmodel
    primarykey
    data
    text
    <p>Ok I know this is a long shot.</p> <p>I am using asp.net mvc on the backend. I will have an action that will return a json viewmodel that will have several simple properties as well as objects and collections of objects on it. For instance</p> <pre><code>public class ViewModel { public string Name {get;set;} public Person Person {get;set;} public IEnumerable&lt;SleectListItem&gt; UserTypes {get;set;} } public class Person { public string FirstName {get;set;} public string LastName {get;set;} public int UserType {get;set;} } </code></pre> <p>a SelectListType is just a name value pair with "Text" and "Value" and "Selected" properties on it</p> <p>The idea is that there is a form where you can create a person by filling out there first name, last name and selecting a usertype from a dropdown list.</p> <p>What I would like to be able to do is have a set of backbone.js models such as</p> <pre><code>app.MyViewModel=Backbone.Model.extend(); app.Person=Backbone.Model.extend(); app.SelectListItem=Backbone.Model.Extend(); app.UserTypes=Backbone.Collection.Extend({ model:app.SelectListType }) </code></pre> <p>and be able to populate the MyViewModel by passing in the Json returned from the server which would be something like this</p> <pre><code>{Name:'SomeName', Person:{ FirstName:'Frank', lastName:'Jones' }, UserTypes:[{Text:'Admin', Value:1, selected:false}, {text:'peon', Value:2, selected:false} </code></pre> <p>This is not the traditional way I know. I guess I'm supposed to have one call for each object or something but I really want to only have one call to the server to get all the data I need as it's already being collected and arranged properly on the server.</p> <p>I could write all kinds of loops to populate all the different collections and so on once the data arrived but is there not some more efficient manner of doing this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload