Ruby on rails 主干和轨道取数
因此,我使用model.fetch引入了一个模型 那个模型有一个集合。json包含一个数组(stops)。 模型中的集合正被数组覆盖,因为model.fetch返回的json包含该集合。这有什么办法吗Ruby on rails 主干和轨道取数,ruby-on-rails,ruby,json,ruby-on-rails-3,backbone.js,Ruby On Rails,Ruby,Json,Ruby On Rails 3,Backbone.js,因此,我使用model.fetch引入了一个模型 那个模型有一个集合。json包含一个数组(stops)。 模型中的集合正被数组覆盖,因为model.fetch返回的json包含该集合。这有什么办法吗 App.Models.Itinerary = Backbone.Model.extend({ url: '', ID: "", Name: "", stops: new App.Collections.StopCollection(), 然后我调用window.i
App.Models.Itinerary = Backbone.Model.extend({
url: '',
ID: "",
Name: "",
stops: new App.Collections.StopCollection(),
然后我调用window.investure.fetch()
和stops现在是一个数组(具有正确的数据)
我得到的回报是
(模型)
(收集)
您的控制器方法在Rails中看起来像什么?@BrendanBenson
def show inventary=inventary.find(params[:id])render json:inventary end
,它使用inventary.rbdef as_json(option={})super({id:self.id,Name:self.Name,include:[:stops]})结束
我的意思是我的json回来了,就像我猜的那样?Just backbone.js就像一个数组,用数组覆盖属性stops(类型为StopCollection())。
{"ID":"7cd9dcdc-54f1-4704-a8be-393d67559b7e","Name":"China","stops":
[{"ID":"1","Name":"Jordan Stop","Notes":"Ayo Notes!","OrderNumber":null},
{"ID":"5","Name":"Another Jordan Stop","Notes":"Aya Notes :-!","OrderNumber":null}]}