我有一个如下数组:
var dataPushArray = [
{
"name" : "name1", //Name for reference
"event": "event1", //Event to be passed
"catagory": "catagory1", //Catagory to be passed
"action": "action1", //Action to be passed
"label": "label1", //Label(s) to be passed
"trigger": "views-ac-dependent-filter", //Class or ID of click
element
},
{
"name" : "name2", //Name for reference
"event": "event2", //Event to be passed
"catagory": "catagory2", //Catagory to be passed
"action": "action2", //Action to be passed
"label": "label2", //Label(s) to be passed
"trigger": "edit-submit-hiscox-marklerportal-search", //Class or ID of click element
}
];
我有一个click事件,它查看数组中的所有“触发器”,如果单击一个,则执行以下操作:
//Define vars
var clickTriggers = [];
var pushData = "";
//Loop through all results
for(i=0;i<dataPushArray.length;i++){
//Merge click selector with click trigger
var trigger = String(dataPushArray[i].trigger);
//Puts all individual click triggers in clickTriggers array
clickTriggers.push(trigger);
}
//Click function for all click triggers
$(clickTriggers.join(',')).on('click', function(trigger) {
if(jQuery.inArray(trigger, dataPushArray)) {
//Output data here
}
})
哪个工作正常,但是我想做的是单击特定元素后从数组中获取所有值,例如,如果单击了带有触发器“ views-ac-dependent-filter”的元素,那么我想获取阵列那部分的名称,事件,类别和标签。
任何对此的帮助将不胜感激