I need to get right listbox columns data from json
My json is as follows:
[
{
"CustName": "Matt Harrison",
"name": "Steve Rucci",
"functionRoom": "Living Room",
"bookingId": "659",
"bookingName": "Matt Booking for Lost Business Report Sept 11",
"postAs": ""
}
]
I applied a customized function
copyObjectProps(source, keys) {
let newObject = {}
keys.forEach(function(key) {
newObject[key] = source[key]
})
return newObject
}
on button click First I prepare list of Columns
$("#button").click(function(){
var s='';
$("Listbox > option").each(function() {
s+="'"+this.text+"',";
});
s=s.replace(/,+$/,'');
objBookingReports.RS_FN_FunctionList=s;
})
then this list goes to copyObjectProps() function and create filtered json object
var filteredparam1 = new Array();
var x =objBookingReports.RS_FN_FunctionList;
// x value is "'bookingId','bookingName'"
x = x.replace(/^"\?/, '');
x=x.replace(/"+$/,'');
var y=[x];
$.each(jsonData, function(key, value){
filteredparam1.push(objBookingReports.copyObjectProps(value,y))
});
console.log(filteredparam1)
}
the problem is here in formatiing . when i place column list in y=[x]; .it is not retuning json data with selected columns . but if i tried tried to place hardcore value like
var y=['bookingId','bookingName'];
then it is showing me results . please suggest how can i format my column list correctly ?