【发布时间】:2016-10-27 20:11:25
【问题描述】:
为了更清楚而编辑的问题!
我正在构建一个 angular-rails 应用程序,但在解析数组时遇到了问题。我的一个 ActiveRecord 模型有一个属性数组。 在我的 Rails 控制器中,在它到达我的 Angular 应用程序之前,数组看起来像这样:
def show
@thing = Thing.find(params[:id])
# @thing.list => ["{\"content\"=>\"first index\"}", "{\"content\"=>\"second index\"}"]
render json: @recipe
end
# resulting json for @thing:
{
id: 1,
title: "thing",
list: [
"first index",
"second index"
],
}
然后在我的角度控制器中,数组属性看起来像:
thing.list => ["{"content"=>"one"}", "{"content"=>"two"}"]
当然我需要它看起来像:
[{content: "one"}, {content:"two"}]
我在应用程序的 Rails 和 Angular 端都尝试过 JSON.parse,但没有成功。
【问题讨论】:
标签: javascript ruby-on-rails angularjs json