Is it acceptable to "dependency-inject" more than one models into a View on initialized()
in Backbone?
For example:
var myView = new MyView({
model: {
category: categoryModel,
name: nameModel,
tag: tagModel
}
})
Model contains dynamic data and its logic. It performs various types of action on the data like validation, conversion, computed properties, access control etc. 1. It extends Backbone.
Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.
BackboneJS is a lightweight JavaScript library that allows to develop and structure the client side applications that run in a web browser. It offers MVC framework which abstracts data into models, DOM into views and bind these two using events.
Absolutely, it is acceptable!
There are common practices for working with models and views - most notably, people usually pass a Backbone model in to a view. However, there's no rules for what a view's model
should or should not be.
The real key is that your team (if you have one) understands what you're doing and why. If you're going to use this pattern in your app, then the team needs to know what signs to look for and what the common patterns are for when and why you would do this.
(Along those lines, but not really directly a part of my answers... I would ask: why do you want to do this? Do you really need three separate models to do what your view needs? Or are you perhaps missing an abstraction in the form of a single view model that should encapsulate all of the data you need.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With