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

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

问题描述

我正在使用bone.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 .

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

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