我想处理从 Sencha 中的 rails 发送的嵌套 JSON 数据。
在 Rails 中,我的模型关联是:
class User < ActiveRecord::Base
has_many :codes
has_many :stores, :through => :codes, :uniq => true
class Store < ActiveRecord::Base
has_many :deals
has_many :orders
has_many :rewards
has_many :codes
has_many :users, :through => :codes, :uniq => true
class Code < ActiveRecord::Base
validates :unique_code, :uniqueness => true
belongs_to :store
belongs_to :order
belongs_to :user
belongs_to :earn
可以看到,Code类存储了User和Store之间的所有关系信息。
现在,我可以使用将嵌套的 JSON 发送到 sencha
@user.to_json(:include => :stores, :deals, :rewards) (not proper code)
但是如何处理 Sencha 中的嵌套结构?我的目标基本上是有一个 ListPanel,它首先列出并显示用户订阅的商店,当点击时,会加载关系的详细信息,例如商店当前提供的交易和奖励。
我在 Sencha 中看不到“有很多通过”关系的选项。
谢谢您的帮助。