如何选择我的as_json方法?

时间:2018-01-23 07:10:29

标签: ruby-on-rails json

现在我在我的模型中使用了as_json方法

  def as_json(options = {})
{
    id: id,
    diary_id: diary_id,
    title: title,
    post_date_gmt: date,
    post_content: strip_tags(content),
    smiley_id: smiley_id,
    author_id: user_id,
    author_name: user.display_name,
    attachments: filter_attachments(options[:version]),
    root_comments: format_comments(nested_comments.arrange(:order => :created_at)),
    post_readings: post_readings.size,
    is_read: read_by(options[:current_user])
}
end

我需要稍微更改一下这个结构,实际上我希望按日期对这个数组进行分组。

{
  date_01: {
    [post1], [post2], [post3]
   },
  date_02: {
    [post1], [post2], [post3]
   }
}

我该怎么办?

2 个答案:

答案 0 :(得分:0)

我已按以下步骤解决了该问题

 <button type="button" [disabled]="registerForm.invalid">Register</button>

答案 1 :(得分:-1)

将数据键的值替换为数组数组。如下。

{
  date_01: [
    [post1], [post2], [post3]
   ],
  date_02: [
    [post1], [post2], [post3]
   ]
}
相关问题