Do Backbone.js queries require jQuery or Zepto? (Or: why do I get "Uncaught TypeError: undefined is not a function"?)

Im just starting with Backbone.js. Ive subclassed Backbone.Model and Backbone.View :

 var Message = Backbone.Model.extend(); var MessageView = Backbone.View.extend({ tagName: 'div', className: 'message', template: _.template('{{ html }}'), render: function(){ this.template({ html: this.model.html }); this.el.className.append(' ' + this.model.type); return this; } }); 

Then I tried to create an instance of each of them:

 var message = new Message({html: html, type: type}); var messageView = new MessageView({model: message}); 

The last line leads to an error (in Chrome 12): Uncaught TypeError: undefined is not a function . It returns this error back to the f.extend.make function in Backbone.js.

The Backbone.js documentation on view.make says:

Convenience function for creating a DOM element of this type (tagName) with additional attributes and HTML content. Used internally to create the initial view.el

  • Is jQuery or Zepto required?
  • Can I remove this dependency by overriding view.make in my call to Backbone.View.extend ?
+4
source share
2 answers

1) The documentation states that this requires

either jQuery (> 1.4.2) or Zepto.

2) The View component is closely related to the jQuery / Zepto API. You can override it, but if you make extensive use of backbone.js, you will override the whole interface.

But maybe it works with your little use case, but because of the tight connection, I cannot guarantee that it works.

+5
source

You can also use Spine.js instead of the main one.

It is also compatible with jQuery and Zepto, but not needed for templates.

Spine.js also does not need to be underlined, but you can add it as a plugin if you need to.

To learn more about good, click here .

Spine.js uses the concept of a controller to bind a data model to elements.

+4
source

All Articles