简体   繁体   中英

How to use multiple extensions in Backbone.Model.extend?

I am working on a project that creates models in such a manner.

Backbone.DeepModel.extend({
  ...
});

This deepmodel allows for deeply nested attributes to be refereed via sytax such as

containerGrid.get('cols')[0]['content']

Now I have to implement nested models in a one-to-many format. Deep model doesn't support this, but a library called backbone-relational.js does. The syntax for this library is

Backbone.RelationalModel.extend({
  ...
});

The functionality for these libraries does not overlap, and it is not possible for me to rewrite all of the code currently implemented with the Backbone.Deepmodel syntax. Is there another library I can use which supports both functionalities or another workaround you might recommend?

Thank you very much for reading, I really appreciate your time and effort!

Just extend from both classes.

You can provide any object to .extend , not just an object literal. Extend your own class from Deepmodel , then extend a new class from RelationalModel , providing the Deepmodel -extended class's prototype:

var MyModel = Backbone.Deepmodel.extend({ ... })

MyModel = Backbone.RelationalModel.extend(MyModel.prototype);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM