No crearía URL anidadas a menos que realmente tenga un buen argumento para ello. Cada recurso se puede definir por un nombre de recurso y un id. La relación entre los objetos es interna.
http://foo.com/a/:id.json
http://foo.com/b/:id.json
http://foo.com/c/:id.json
Dicho esto, muchos éxitos al servidor para extraer objetos anidados no son realmente ideales. Usted está teniendo mejor un único recurso que devuelve JSON anidada
http://foo.com/a/:id.json
Por ejemplo los datos vuelva de mi servidor parece
{
"id": 372,
"context": "office_work",
"date_of_entry": "2011-7-05 15:22:00",
"blood_glucose_measurement": 98,
"food": {
"exchanges": "98",
"list": "burger fries"
},
"exercise": {
"duration": "28",
"list": "running shopping"
}
}
Los subnodos se ensamblan mediante un controlador personalizado que toma al individuo db graba y crea un árbol de datos.
Sin embargo, ahora tiene problemas porque backbone.js sólo admite estructuras planas de forma nativa. Realicé algunas modificaciones al Backbone.Model básico para admitir el procesamiento de estructuras tipo árbol.
Lo pegaré aquí si le puede ser útil.
#= require jquery
#= require underscore
#= require backbone
#
class RailsModel extends Backbone.Model
initialize: (attributes) ->
data = {}
for k,v of @attributes
if v.constructor.name == "Object"
data[k] = new RailsModel(v)
@set data, {silent: true}
get: (field)->
val = @
first = true
for p in field.split('/')
if first
val = super(p)
else
# This allows returning *undefined* rather
# than an exception if the parent of a deeply
# nested node does not exist.
val = if val? then val.get(p) else undefined
first = false
val
# Allow heirarchical setting of objects
#
# Example
#
# model.set_field('root/child', 10)
#
# Will create the path if it does not exist
set_field: (field, value, silent=false)->
path = field.split('/')
node = undefined
val = @
for p in field.split('/')
node = val
val = node.get(p)
if not val?
data = {}
val = new RailsModel
data[p] = val
node.set data
data = {}
data[p] = value
node.set data
if not silent and /\//.test(field)
@trigger("change:#{field}", @model, value)
@trigger("change", @model)
window.RailsModel = RailsModel
Se puede utilizar como
model = new RailsModel
model.url = "/data"
model.fetch()
model.get('excercise/duration')
model.set_field('excercise/duration', 25)
La última línea se activará un evento "cambio: ejercicio/duración"