我想使用 JavaScript 使用地图。
如果我使用静态数据,我可以获得预期的输出。
var tempMap={91: "Live", 41: "Aggr-Pack", 92: "Test", 118: "Group", 115: "Inner Cartons", 122: "SNDC", 102: "Web Service", 82: "EXTERNAL_DEF", 137: "PARTIAL", 72: "Return", 112: "Kit Master Cartons", 46: "SHIP", 134: "VEHICLE_TYPE", 121: "SGTIN", 135: "VEHICLE_ID", 45: "DE-COM", 113: "Bulk Cartons ", 136: "VEHICLE_COLOR", 131: "CARRIER", 52: "Invoice Number", 101: "File", 114: "Product Master Cartons ", 81: "GLN", 42: "Kit", 53: "Shipping Number", 47: "RECEIVE", 111: "Pallet", 133: "SHIPMENT_TYPE", 71: "Sale", 43: "DIS", 116: "Kits", 21: "en", 123: "SSCC", 22: "es", 117: "Products", 44: "COM", 132: "EXPECTED_DELIVERY_DATE", 73: "Transfer", 51: "Purchase Order Number"};
var key=116;
alert(tempMap[key]);
我想从响应中创建动态地图。
回应是
"{91=Live, 41=Aggr-Pack, 92=Test, 118=Group, 115=Inner Cartons, 122=SNDC, 102=Web Service, 82=EXTERNAL_DEF, 137=PARTIAL, 72=Return, 112=Kit Master Cartons, 46=SHIP, 134=VEHICLE_TYPE, 121=SGTIN, 135=VEHICLE_ID, 45=DE-COM, 113=Bulk Cartons , 136=VEHICLE_COLOR, 131=CARRIER, 52=Invoice Number, 101=File, 114=Product Master Cartons , 81=GLN, 42=Kit, 53=Shipping Number, 47=RECEIVE, 111=Pallet, 133=SHIPMENT_TYPE, 71=Sale, 43=DIS, 116=Kits, 21=en, 123=SSCC, 22=es, 117=Products, 44=COM, 132=EXPECTED_DELIVERY_DATE, 73=Transfer, 51=Purchase Order Number}"
我使用下面的 javascript 代码修改了 tempMap 数据中给出的响应。
var map=(str.replace(/=/gi,"\"= \"").replace(/,/gi,"\",\"").replace(/=/gi,":"));
map="{\""+map.substring(2,(map.length)-1)+"\"}"
但是我无法通过传递键值来获得输出。我不想使用任何其他第三方来执行此操作。