我有一个可以有孩子的Rails模型,JSON中的一个例子如下:
{"content":"123",
"created_at":"2013-08-23T22:17:03Z",
"folder_id":4,
"id":135,
"parent_id":null,
"title":"Will this succeed? 1234",
"updated_at":"2013-08-23T22:17:03Z",
"user_id":2,
"children":
[{"content":"123","created_at":"2013-09-05T03:52:05Z","folder_id":4,"id":189,"parent_id":135,"title":"123","updated_at":"2013-09-05T03:52:05Z","user_id":2}]
}
我的问题是这些JSON对象中的每一个都变成了D3节点,我需要能够根据children
数组是否为空来执行操作。但是,我在submissions.children
上执行了一个console.log,它返回undefined
。那是为什么?
更新 这是我的提交控制器中的show动作:
def show
respond_to do |format|
format.js
format.json {render json: @submission.as_json(include:[:children])}
format.html
end
end