JSF: parse JSON and add new Item
来源:互联网 发布:zard变声器数据 编辑:程序博客网 时间:2024/05/01 22:07
I have to retrieve the content in data-birf-extra in the following script:
<a href="" data-birf-log="component" data-birf-par="mdot_v_lstg_1" data-birf-extra="{'c':'569710','v':'282188481','pg':'mdot_mya_qsc'}" data-birf-cmp="mdot_delt_car">
In javascript, I used:
//get all listings in an arrayvar savedListings=$('[id$=savedListingsPanel]').find(".savelisting-button .savelisting-trigger.favorite");
Since, there are multiple dom elements found by the above selector, so
//fire bi for each $.each(savedListings,function(index,listing){ var par=$(listing).attr('data-birf-par'); var extra=$(listing).attr('data-birf-extra'); var jsonExtra=JSON.parse(extra.replace(/'/g, '"')); jsonExtra['cmp']="mdot_my_dtc"; jsonExtra['et']="click"; if ($(listing).attr("data-birf-par")) { jsonExtra['par']=par; window.BIRF.log(jsonExtra,'event'); } else { window.BIRF.log(jsonExtra, 'event'); } });
The following are the issues I had:
1. JSON.parse(extra) not work, it complains "Uncaught SyntaxError: Unexpected token ' in JSON at position 1(…). "
reason: extra contains single quotation which is not a valid character when use JSON.parse()-----> need to verfiy?
solution: replace all single quotation with double quotation using .replace(regex, value)
var jsonExtra=JSON.parse(extra.replace(/'/g, '"'));
JSON.stringify(...); // convert json object into a string by adding double quotations
JSON.parse(...); // convert string to a json object by removing double quotations
2. Add new filed to json object:
jsonExtra['cmp']="mdot_my_dtc"; jsonExtra['et']="click";
3. fire birf:
window.BIRF.log(jsonExtra,'event'); //fire bi_event window.BIRF.log(jsonExtra,'subpage'); //fire bi_page
0 0
- JSF: parse JSON and add new Item
- JSON Parse and Stringify
- SharePoint 隐藏Add New Item
- json.parse() and json.stringify()
- Delphi Open Tools API - How to create and add new menu item
- JSON.parse, JSON.stringify and eval
- C# Call Web API and Parse JSON
- Web and php parse json data
- How to add new item to the Context Menu
- Parse JSON
- JSON.parse
- JSON.parse()
- JSON.parse()
- JSON.parse()
- Add Ribbon button and menu item in Sharepoint 2010
- The increment of remove and add live data item behavior
- How to add a new user in linux and add it to a new group
- JSON.parse() JSON.stringify()
- 表单提交return方法与ajax冲突解决办法
- chaincode:simpledemo
- 第一个Java程序
- 第十五章 编程练习
- [Leetcode] 18. 4Sum 解题报告
- JSF: parse JSON and add new Item
- 网上一篇非常好的讲socket的send和recv的
- JS基本解释
- Shell循环遍历每个元素都是变量的数组
- [Leetcode] 19. Remove Nth Node From End of List 解题报告
- How to get simple dispatch from this.props using connect w/ Redux?
- [Leetcode] 20. Valid Parentheses 解题报告
- Posix IPC
- Leetcode 213. House Robber II