我正在尝试找出一个 Collection/Model 系统,它可以根据所要求的上下文来处理检索数据,例如:
可用的“根”资源:
/api/accounts
/api/datacenters
/api/networks
/api/servers
/api/volumes
可用的“子”资源:
/api/accounts/:id
/api/accounts/:id/datacenters
/api/accounts/:id/datacenters/:id/networks
/api/accounts/:id/datacenters/:id/networks/:id/servers
/api/accounts/:id/datacenters/:id/networks/:id/servers/:id/volumes
/api/accounts/:id/networks
/api/accounts/:id/networks/:id/servers
/api/accounts/:id/networks/:id/servers/:id/volumes
/api/accounts/:id/servers
/api/accounts/:id/servers/:id/volumes
/api/accounts/:id/volumes
然后,给定 Collection/Model 系统,我将能够执行以下操作:
// get the first account
var account = AccountCollection.fetch().first()
// get only the datacenters associated to that account
account.get('datacenters')
// get only the servers associated to the first datacenter's first network
account.get('datacenters').first().get('networks').first().get('servers')
不确定这是否有意义,所以如果我需要澄清任何事情,请告诉我。
关于我为什么要能够做到这一点的最大问题是,如果account.get('datacenters').first().get('networks')
尚未发出请求(即或者可以是fetch()
d 也许?)
您可以提供的任何帮助将不胜感激!