开发者

Which Javascript MVC framework best handles relational data?

开发者 https://www.devze.com 2023-04-01 09:04 出处:网络
I\'m looking to try, for the first time, a JavaScript MVC framework like Knockout, Backbone.js, Spine, JavaScriptMVC, etc.

I'm looking to try, for the first time, a JavaScript MVC framework like Knockout, Backbone.js, Spine, JavaScriptMVC, etc.

I've started looking at some of the documentation available for these frameworks and I'm having trouble finding examples of how they handle relational data. Most of them use a ToDo list as an example. A ToDo list is nice, but it doesn't cover relational data. Perhaps a better example would be a cookbook with a model for both recipes and ingredients:

var Recipe = function(){
   this.name = "Pizza";
   this.description = "A delicious baked, flat, disc-shaped bread topped with tomato sauce and cheese.";
}

var Ingredient = function(){
   this.name = "Tomato sauce"
}

var IngredientToRecipe = function(){
   this.recipe = null;
   this.ingredient = null;
   this.quantity;
}

The example开发者_运维百科s for models that I've seen so far do not seem to deal with the problems of relationships: foreign keys, id generation, etc. The example above is a many-to-many relationship, but I would be happy with support even for one-to-many relationships.

I really like the things provided by these frameworks:

  • changes to the models automatically update the view (i.e. DOM)
  • automatically updating the model on the server when it changes
  • clear organization of code
  • etc...

But, I'd like advice on which framework best handles relationships between models and has an example where that is done.

Thanks!


While Backbone (intentionally) doesn't support models containing other models/collections very gracefully, Backbone-relational adds support for it and works quite well. Check out their documentation.


Sproutcore has a client side datastore which allows you to relate different model object to each other in toOne, toMany, and ManyToMany relationships. You can actually write queries against the store which automagically update when the data changes. Similarly, if you do an update and a model object changes, any views attached to that model (via a controller) will automatically update). Also, SC has a nested store functionality which allows you to abandon changes seamlessly, for the 'save or cancel' type workflows.

http://guides.sproutcore.com/records.html


I don't think you're looking for MVC per se, I think you're looking for something with a good "M". So you might be looking for something like our Ext JS model associations. (Ext JS is of course, a full on framework, so if you're looking to sprinkle something on top of jQuery, it won't be for you.)

Here is the documentation for models in Ext JS 4 and here is the top level guide for Ext JS 4 MVC

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号