Immutablejs:如何反序列化复杂的JS对象

时间:2015-10-26 23:41:40

标签: javascript immutable.js

如果我从普通JSON服务器接收数据,如下所示:

{
    "f223dc3c-946f-4da3-8e77-e8c1fe4d241b": {
        "name": "Dave",
        "age": 16,
        "jobs": [{
            "description": "Sweep the floor",
            "difficulty": 4
        },{
            "description": "Iron the washing",
            "difficulty": 6
        }]
    },
    "84af889a-8fc9-499b-a6ea-97e7a483130c": {
        ...
    }
}

我是否需要遍历所有jobs并将其转换为Map s,然后将每个对象的jobs转换为List,然后将整个转换为Map def task_params params.require(:task).permit(:executor_id, :name, :content, :deadline, :task_name_company) .merge(assigner_id: current_user.id) end class Task < ActiveRecord::Base belongs_to :assigner, class_name: "User" belongs_to :executor, class_name: "User"

或者ImmutableJS是否以递归的方式为我做这件事?

1 个答案:

答案 0 :(得分:1)

正是为Immutable.fromJS()设计的。