骨干视图从两个视图扩展而来

时间:2013-09-28 21:41:14

标签: backbone.js backbone-views

我有两个骨干视图,我想使用第三个视图,它将从两个视图中扩展而来

view1 = Backbone.View.extend({}); view2 = Backbone.View.extend({}); view3(从view1和view2扩展) 任何人都可以帮助我

2 个答案:

答案 0 :(得分:0)

我没试过,但这应该有效,取自: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])

答案 1 :(得分:0)

我发现这个解决方案更容易,在你的情况下会是:

using (var context = new TestEntities()) 
{ 
    var myClients = context.Clients.SqlQuery("SELECT * FROM dbo.Clients").ToList(); 
}

Backbone示例: http://jsfiddle.net/M5J8Q/1809/

木偶的例子: http://jsfiddle.net/M5J8Q/1810/

你也可以这样做:

_.extend(view3.prototype, view1.prototype, view2.prototype);

小提琴:http://jsfiddle.net/M5J8Q/1811/

问候!