Backbone.js - 以 RESTful 方式处理模型关系 [英] backbone.js - handling model relationships in a RESTful way

查看:21
本文介绍了Backbone.js - 以 RESTful 方式处理模型关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用backbone.js

I'm using backbone.js

例如,假设我们有一个产品"模型和一个类别"模型,它们具有多对多的关系.在我的一个观点中,假设我需要检索所有类别的列表,并了解每个类别是否与当前产品型号相关.

For example, let's suppose we have a "products" model and a "categories" model which have a many-to-many relationship. In one of my views, say I need to retrieve a list of all categories and know whether or not each one is related to the current product model.

我是否设置了一个类别"集合并让它成为我的模型的一个属性,并以某种方式让它访问模型的 id,以便在获取它时,它只获取相关的类别?然后我可以获取所有类别并交叉检查它们以查看哪些是相关的,同时还有哪些不相关?

Do I set up a "category" collection and have it be a property of my model and somehow give it access to the id of the model so that when it is fetched, it only gets the categories that are related? And then I could fetch all categories and cross examine them to see which ones are related while still having the ones which are not?

我不知道这样做的最佳方法是什么.我习惯于使用 ORM,这在服务器端很容易.

I have no idea what the best way to do this would be. I'm used to using an ORM which makes it easy on the server-side.

推荐答案

查看 backbone-relational.

这篇关于Backbone.js - 以 RESTful 方式处理模型关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆