The javascript inlining.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

The javascript inlining.

smallfish
Hi,
The javascriptt mode for inlining is a powerful and useful function.But there have some small mistakes.
For example,there have the following codes in javascripts.

var colNames=[ /*[[#{resource.id}]]*/'id',
                     /*[[#{resource.name}*/'name',
                     /*[['#{resource.value}*/'value'];

The result of executing this will be:

var colNames=[ 'id';
                     'name';
                     'value';];

Therefore, the browser prompts this line of code is wrong.
Is it a bug or I used wrong?


Reply | Threaded
Open this post in threaded view
|

Re: The javascript inlining.

danielfernandez
Administrator
Hi,

The current javascript inlining mechanics in Thymeleaf do not allow:

smallfish wrote
var colNames=[ /*[[#{resource.id}]]*/'id',
                     /*[[#{resource.name}*/'name',
                     /*[['#{resource.value}*/'value'];
...because everything after the /*[[ ... ]]*/ will be removed and substituted by ";". This is what allows your scripts to work both in static and in "executed" mode.

The non-commented mechanism would work OK for you, but this has the disadvantage that your scripts would not work in static (non-executed) mode.

So, I'd recommend you a quite neat solution:


    var idColName = /*[[#{resource.id}]]*/ 'id';
    var nameColName = /*[[#{resource.name}]]*/ 'name';
    var valueColName = /*[[#{resource.value}]]*/ 'value';

    var colNames=[ idColName, nameColName, valueColName ];


Regards,
Daniel.