长话短说。
我从后端团队获得了一个具有以下输出的hashMap。
{12 =其他服务(辅助),2 =其他服务,4 =收集,17 =获取新(适合我),19 =获取新服务(适用于我的业务)}
我是一个前端开发者,从未使用过像这样的字符串。由于' ='
,我无法使用jquery.split()拆分它在线搜索我发现了很多我的问题的答案,但是如果它确实是我问题的正确答案,那么就无法解决问题。
以下是我尝试过的内容。 $ {departmentHash}就是一个例子。我想,我的实际代码不会产生任何影响。
How to iterate HashMap using JSTL forEach loop?
(select x_item.pick_area,x_item.awkward_item,x_ploc.pick_location,
(case when x_prod.normal_pick_area = '0' then 'Z'
when x_item.pick_area = '1' then 'A'
when x_item.pick_area = '2' then 'B'
when x_item.pick_area = '3' then 'C'
when x_item.pick_area = '4' then 'D'
when x_item.pick_area = '5' then 'E'
when x_item.pick_area = '6' then 'F'
when x_item.pick_area = '7' and substr(x_ploc.pick_location,3,2) < 22 and
x_prod.awkward_item = 'YES' then 'G'
when x_item.normal_pick_area = 'APR' and substr(x_ploc.pick_location,3,2)
< 22 and x_item.awkward_item = 'NO' then 'H'
when x_item.pick_area = 'APR' and substr(x_ploc.pick_location,3,2) > 21
and x_item.awkward_item = 'NO' then 'I'
when x_item.pick_area = 'APR' and substr(x_ploc.pick_location,3,2) > 21
and x_item.awkward_item = 'YES' then 'J'
else 'Unknown' end) area from x_item)
上述内容并未将任何内容返回到$ {department}
其他链接有类似的答案,我无法开始工作。
How to loop through a HashMap in JSP?
How to iterate an ArrayList inside a HashMap using JSTL?
我可能会误解我的问题,所以如果有人为我提供正确的链接或回答我的问题,我们将不胜感激。
答案 0 :(得分:1)
解析你提供的字符串因为键部分中的整数(12,2,4等)而无法工作。
如果您以字符串的形式获取hashmap数据,您可以在javascript中尝试以下内容:
var str = '{12=Other Services (Assisted), 2=Other Services, 4=Collect, 17=Get New (For Me), 19=Get New (For My Business)}';
str = str.replace('{','');
str = str.replace('}','');// these lines will remove the leading and trailing braces
var arr = str.split(','); // this will give you an array of strings with each index in the format "12=Other Services (Assisted)"
arr.forEach(function(item){
// here you can split again with '=' and do what is required
var s = item.split('=');
var obj = {key: s[0], value:s[1]}; // this is up to your implementation
})