Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

yammer/backbone-component

Repository files navigation

Backbone Component Build Status

A thin layer on top of Backbone's view class to add nested child views.

Install

To install project dependencies:

make install

Testing

To run tests in development mode:

make testem

To run tests in continuous integration mode:

make

Usage

var message = new MessageView();
var reply = new ReplyView();

message.add(reply);
message.render();

Will render:

<div class="message">
  <div class="reply">
  </div>
</div>

See examples directory for more.

API

append(child, [selector])

alias: add

Adds a child view to the end of the view's element. Optionally define the selector to attach to, which defaults to $el.

prepend(child, [selector])

Adds a child view to the beginning of the view's element. Optionally define the selector to attach to, which defaults to $el.

empty()

Removes all child views.

renderTemplate([data])

Renders the view's template with supplied data. Defaults to using underscore templates, but can be overriden by replacing the renderer prototype property with any object that responds to compile and returns a function which renders the template with the supplied data, e.g:

Backbone.Component.prototype.renderer = {
  compile: function(template) {
    return _.partial(Mustache.render, template);
  }
};

About

A thin layer on top of Backbone's view class to add nested child views.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published