admin管理员组文章数量:1325510
I’m just starting out with Backbone.js. I’ve 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;
}
});
I’ve then attempted to create an instance of each:
var message = new Message({html: html, type: type});
var messageView = new MessageView({model: message});
The last line line causes an error (in Chrome 12): Uncaught TypeError: undefined is not a function
. It traces this error back to the function f.extend.make
in Backbone.js.
The Backbone.js documentation on view.make
says:
Convenience function for creating a DOM element of the given type (tagName), with optional attributes and HTML content. Used internally to create the initial
view.el
.
- Does it require jQuery or Zepto?
- Could I remove this dependency by overriding
view.make
in my call toBackbone.View.extend
?
I’m just starting out with Backbone.js. I’ve 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;
}
});
I’ve then attempted to create an instance of each:
var message = new Message({html: html, type: type});
var messageView = new MessageView({model: message});
The last line line causes an error (in Chrome 12): Uncaught TypeError: undefined is not a function
. It traces this error back to the function f.extend.make
in Backbone.js.
The Backbone.js documentation on view.make
says:
Convenience function for creating a DOM element of the given type (tagName), with optional attributes and HTML content. Used internally to create the initial
view.el
.
- Does it require jQuery or Zepto?
- Could I remove this dependency by overriding
view.make
in my call toBackbone.View.extend
?
2 Answers
Reset to default 51) The documentation states that it requires
either jQuery ( > 1.4.2) or Zepto.
2) The View Component is tightly coupled to the jQuery/Zepto API. You could reimplement it, but if you use backbone.js extensively, you will reimplement the whole interface.
But maybe it works with your small use-case, but becuase of the tight coupling I would not guarantee that it works.
You also can use the Spine.js instead backbone.
It's also patible with JQuery and Zepto, but isn't needed to templating.
Spine.js don't need underscore too, but you can add as plugin if you need.
To know more about a good review here.
Spine.js uses the controller concept to bind data model with elements.
本文标签:
版权声明:本文标题:javascript - Do Backbone.js views require jQuery or Zepto? (Or: why am I getting “Uncaught TypeError: undefined is not a functio 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742197354a2431322.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论