Api and options

SimpleView.extend(prototypeProperties, [staticProperties])

Used to define view types / constructor functions. Define prototype methods for view via object hash. Static properties are optional.


initialize(options)

Define initialize function in prototype properties if you need to do some logic on view startup. Will receive all arguments from constructor.


assignOptions(boolean)

If defined user passed options will be merged with defaults and written to viewInstance.options. False by default.


defaults(object | function)

Define view default options with object hash or function return object.


optionRules(object)

Options provided by view defaults and and constructor parameters can be type checked as defined here.


            optionRules: {
                instrument: String,
                age: {type: Number, default: 18, validator: function(age) {
                    return age >= 18;
                }},
                mentor: {type: Person, required: false}
                url: [String, Function]
            }
        

events(object | function)

Declare events with object hash or custom function in prototype properties.


            events: {
                'click .selector': 'handler',
                'click {{this.someVariable}}': 'handler', // variable will be injected
                'one:submit form': 'oneSubmit', // handler will run only once
                'resize window': 'onWindowResize',
                'keyup document': 'onDocumentKeyup'
            }
        

addDismissListener(listenerName)

When escape key is pressed or element outside view is clicked view.listenerName will be run.


removeDismissListener(listenerName)

Remove dismiss listener identified via listenerName.


delegatedEvents: true | false

Events are delegated to view by default. If you want to bind them directly to elements (to avoid excessive bubbling on views with complex dom tree) set "delegatedEvents" to false.


addView(viewInstance)

Adds view instance to sub view registry. This binding enables effective cleanup of container views.


mapView(selector, View, [params])

Create View instance with first element inside current view found via selector. Returns mapped instance.


mapViews(selector, View, [params])

Map View instances to all elements inside current view found via selector. Returns mapped instances array;


removeViews()

Removes all registered sub views.


$(selector)

Alias for this.$el.find(selector);


trigger(eventName, [data])

Trigger custom event and optionally provide data to handler callback.


on(eventName, callback)

Subscribe to custom view events


off([eventName, [callback]])

Removes listeners to custom view events.


listenTo(publisher, eventName, callback)

Listen to other object events.


stopListening([publisher, [eventName, [callback]]])

Removes listeners to custom publisher events.


remove()

Removes view from DOM and does cleanup of all bound events.