Imagine that I have a view, and as part of a view it render 'x' model objects, and 'x' only. The question, where is it appropriate for me to put this view related constant?
My guess would be to do something like this:
myApp.MyView = Backbone.View.extend({
...
myConstant: 10,
...
render: function(){
...
//some code that uses myConstant
...
}
});
Does this make sense?
Any suggestions help!
The Backbone. js Views specify how your data looks like. They represent model's data to the users. They can be used with any JavaScript template library. They handle users input events, bind events and methods, render model and collection and interact with users.
The developers should make use of Backbone JS while developing a single-page Java application. Backbone JS features Model View Framework, which allows much more than structuring JavaScript architecture. It will help the developers eliminate several issues that they might be facing while developing apps.
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.
It sounds like what you want to do is to assign a class property to the view. You can pass a second hash into your extend call to do this. Your code would look something like this:
myApp.MyView = Backbone.View.extend({
render: function() {
alert(myApp.MyView.myConstant);
}
}, {
myConstant: 10
});
where your constant is accessible as myApp.MyView.myConstant.
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