如何将数据存储到json中的数组

时间:2017-10-06 07:53:10

标签: ruby-on-rails arrays backbone.js

我有一个json文件,格式如下:

{
  "recipe_type": [
    "vegetarian",
    "non-vegetarian"
  ],
  "recipe_times": [
    "<30min",
    "30-60min",
    "60-90min"
  ],
  "recipe_cuisines": [
    "arabian",
    "european",
    "Indian",
    "chinese"
  ]
}

我需要将每个列表存储到单独的数组中:

@recipe = new JS.M.Recipe()
@recipe.fetch(@recipe.getRecipeType())
@recipeTypes = @recipe.getRecipeType()//Here data is getting as objetcs..if i use alert to print this. It showing output like "[object Object]"..

我想按如下方式存储数据:

@recipe_type = @recipeTypes.get("recipe_type")
@recipe_times = @recipeTypes.get("recipe_times")//This is wrong

我如何实现我的目标?

1 个答案:

答案 0 :(得分:0)

如果您使用的是主干,则必须在页面上加载下划线。如果是,这应该适合你 lists = _.values(data) 其中data是上面提到的JSON对象。