Question

I'm not sure what the right approach here is. I am setting up a simple form. I need a couple of standard HTML input fields and a couple of select inputs. The data is coming from a couple of different sources and I would like to present the models and collections, with their data to the view like so:

Controller:

var registerView = new registrationView.RegistrationForm({  
    model: userModel,  
    model2: departmentCollection  
});
myApp.SomeRegion.show(registerView);

Can I do this? Or do I need to split the form into separate regions, all with their own model or collection. If so, how do I call the model data in the template. I have not been able to make it work so far. I cannot find any examples of a form with mixed fields coming from different models and collections,

Many thanks

Wittner

Was it helpful?

Solution

You can do it using a composite view:

var registrationView.RegistrationForm = Marionette.CompositeView({
   // ...
});

var my View = new registrationView.RegistrationForm({  
    model: userModel,  
    collection: departmentCollection  
});

See https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.compositeview.md and https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.collectionview.md (a composite view inherits behavior from a collection view).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top