I try to add an Export button in ExtJS, it should do URL encoding for the search parameters and pass the generated query string to the export URL.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
{ xtype: 'button', text: 'Export', handler: function(){ var searchParams = { pasm: Ext.getCmp('payment_log_pasm').getValue(), startDate: Ext.getCmp('payment_log_start_date').getValue(), endDate: Ext.getCmp('payment_log_end_date').getValue() }; let qs = Ext.urlEncode(searchParams); console.log(qs); location.href = appBaseUri + '/sys/payment/export?'+qs; } } |
When testing above code in Chrome, following error happened:
Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
The reason is let
keyword is not allowed in non-strict mode for this version of Chrome.
One solution is to change let
to var
. (But it isn't good)
The better solution is to add "use strict" statement.
So the final code should be
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
{ xtype: 'button', text: 'Export', handler: function(){ "use strict"; var searchParams = { pasm: Ext.getCmp('payment_log_pasm').getValue(), startDate: Ext.getCmp('payment_log_start_date').getValue(), endDate: Ext.getCmp('payment_log_end_date').getValue() }; let qs = Ext.urlEncode(searchParams); console.log(qs); location.href = appBaseUri + '/sys/payment/export?'+qs; } } |