我有一个调用php文件的$ .post jQuery调用。该文件然后返回一个JSON编码数组。然后,数组映射到编辑数组中的一些数据。但是,我收到错误arr.map is not function
。jQuery地图不适用于json数组
这是在$ .post调用中传递的数组。
[{"set":"Alpha","key":"256"},
{"set":"Omega","key":"671"},
{"set":"Theta","key":"762"},
{"set":"Beta","key":"462"}]
这是地图功能。
idHash = {'Alpha': '1', 'Beta': '2', 'Theta': '3', 'Omega': '4'};
var arr = arr.map(function(item){
item.set = idHash[item.set]
return item;
})
在映射函数之后,数组应该看起来像这样。
[{"set":"1","key":"256"},
{"set":"4","key":"671"},
{"set":"3","key":"762"},
{"set":"2","key":"462"}]
我得到这个错误。 TypeError:不能使用'in'运算符来搜索''中的'2113',然后列出数组。 – ChrisRockGM
什么是idHash指的是什么?如果用'console.log(item)替换它,'.map()可以工作。 –
'.map()'需要使用$的jquery对象或调用它,比如'$ .map(array,function(){});'。该错误可能与'item.set'代码行一样。 –