我有一个可以有孩子的 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
数组是否为空来采取行动。但是,我执行了 console.logsubmissions.children
并且它回来了undefined
。这是为什么?
更新 这是我的提交控制器中的显示操作:
def show
respond_to do |format|
format.js
format.json {render json: @submission.as_json(include:[:children])}
format.html
end
end