我需要一个js对象转换到另一个对象传递到服务器后,它的键的名称,例如不同有什么办法使用underscore.js
var a = {
name : "Foo",
amount: 55,
reported : false,
...
<snip/>
...
date : "10/01/2001"
}
需要重命名JS对象键变成
a = {
id : "Foo",
total : 55,
updated: false,
...
<snip/>
...
issued : "10/01/2001"
}
在那里我有可用于映射所有键
var serverKeyMap = {
name : "id",
amount : "total",
reported : "updated",
...
date : "issue"
}
查找obj是有没有本功能可以在underscore.js或jQuery中使用,可以使用这个功能吗?
谢谢
不是下划线,但lodash具有[_.mapKeys](https://lodash.com/docs#mapKeys)用于修改对象的键。 – CookieMonster 2015-10-25 14:54:20