I have a javascript object stored in variable dashboard_filter_value_attributes
which hold the tableau filter names which I am trying to send via post to my rails controller for further processing.
when i do console.log(dashboard_filter_value_attributes)
, i see the below output on the console, i have expanded the 0th index key that why you see __proto__: Object
in the below output
{}
0:
filter_name: "Filter One"
__proto__: Object
1: {filter_name: "Filter Two"}
2: {filter_name: "Filter Theree"}
3: {filter_name: "Filter Four"}
4: {filter_name: "Filter Five"}
5: {filter_name: "Filter Six"}
6: {filter_name: "Filter Seven"}
7: {filter_name: "Filter Eight"}
8: {filter_name: "Filter Nine"}
9: {filter_name: "Filter Ten"}
__proto__: Object
I have defined let dashboard_filter_value_attributes = {};
but I am unable to send the object via post. The object is not getting passed and is ingnored during the jQuery.post
execution, i also do not see any error on the console.
Here is my jQuery.post
call
let activeSheet = tableauViz.getWorkbook().getActiveSheet();
let viewName = 'my custom view';
let counter = 0;
let dashboard_filter_value_attributes = {};
activeSheet.getWorksheets().forEach(function(worksheet) {
if (worksheet.getName() == "Filter") {
worksheet.getFiltersAsync().then(function(filterParameterList) {
filterParameterList.forEach(function(fp) {
const name = filter ? fp.getFieldName() : fp.getName();
dashboard_filter_value_attributes[counter] = {
filter_name: name,
};
counter = counter + 1;
}
});
});
});
jQuery.post($('#new_dashboard_filter').attr('action'), {
dashboard_filter: {
name:viewName,
dashboard_filter_values: dashboard_filter_value_attributes
}
});
I have also tried to use JSON.strigify but even then I am not able to post the object to my rails controller.
When i use console.log(JSON.strigify(dashboard_filter_value_attributes));
i see []
Any help in this would be really great. Thanks.