我有两个主干视图,我想使用第三个视图,它将从两者扩展
view1 = Backbone.View.extend({}); view2 = Backbone.View.extend({}); view3(从 view1 和 view2 扩展)谁能帮帮我
我有两个主干视图,我想使用第三个视图,它将从两者扩展
view1 = Backbone.View.extend({}); view2 = Backbone.View.extend({}); view3(从 view1 和 view2 扩展)谁能帮帮我
我没有尝试过,但这应该可以工作,取自:https ://gist.github.com/alassek/1227770
(function () {
function extendEach () {
var args = Array.prototype.slice.call(arguments),
child = this;
_.each(args, function (proto) {
child = child.extend(proto);
});
return child;
}
Backbone.Model.extendEach =
Backbone.Collection.extendEach =
Backbone.Router.extendEach =
Backbone.View.extendEach = extendEach;
})();
ClassC = Backbone.Model.extendEach(ClassA, ClassB, [properties])
我发现这个解决方案更容易,在你的情况下是:
_.extend(view3.prototype, view1.prototype, view2.prototype);
骨干网示例:http: //jsfiddle.net/M5J8Q/1809/
木偶的例子:http: //jsfiddle.net/M5J8Q/1810/
你也可以这样做:
view3.extend(view1.prototype);
view3.extend(view2.prototype);
小提琴:http: //jsfiddle.net/M5J8Q/1811/
问候!