-
Notifications
You must be signed in to change notification settings - Fork 1
Configuration
There are several ways to configure Layouts and managed Views.
There are a number of options you may wish to specify depending on how you wish to use LayoutManager.
To configure at a global level, start with the configure call:
Backbone.Layout.configure({
});From here you specify global values that will appear in options for all
Views (managed by LayoutManager).
There are several predefined defaults that you may wish to change depending on your setup.
Quick access: prefix deferred fetch
partial html insert when
render contains
A string value that will be prefixed to the template property of all
managed Views when fetch is called.
prefix: ""Uses jQuery deferreds for internal operation, this may be overridden to use a different Promises/A compliant deferred.
deferred: function() {
return $.Deferred();
}Uses jQuery to find a selector and returns its innerHTML content as a string
or template function (either works).
fetch: function(path) {
return _.template($(path).html());
}Uses jQuery to find the View's location and inserts the rendered element there. The append property determines if the View should append, defaults to replace via innerHTML.
partial: function(root, name, el, append) {
// If no selector is specified, assume the parent should be added to.
var $root = name ? $(root).find(name) : $(root);
// If no root found, return false
if (!$root.length) {
return false;
}
// Use the append method if append argument is true.
this[append ? "append" : "html"]($root, el);
// If successfully added, return true
return true;
}Override this with a custom HTML method, passed a root element and an element to replace the innerHTML with.
html: function(root, el) {
$(root).html(el);
}Very similar to HTML except this one will appendChild.
append: function(root, el) {
$(root).append(el);
}This function will trigger callbacks based on the success/failure of one or more deferred objects.
when: function(promises) {
return $.when.apply(null, promises);
}Renders a template with the Function or String provided as the template
variable.
render: function(template, context) {
return template(context);
}