[Pas2js] How to insert inline {}

Ondrej Pokorny lazarus at kluug.net
Mon Feb 6 18:53:13 CET 2023


On 06.02.2023 14:30, Michael Van Canneyt via Pas2js wrote:
> On Thu, 26 Jan 2023, Ondrej Pokorny via Pas2js wrote:
>> Hello,
>>
>> I'd like to use the DateTimePicker from https://getdatepicker.com .
>>
>> I declared an external class
>>   TJSTempusDominus = class external name 
>> 'tempusDominus.TempusDominus'(TJSObject)
>>   public
>>     constructor new(aElement: TJSElement);
>>     constructor new(aElement: TJSElement; aOptions: TJSObject);
>>   end;
>>
>> a simple constructor without options works fine:
>>
>>   fDateTimePicker := TJSTempusDominus.new(myElement);
>>
>> Can I somehow add inline options { my-property: false }?
>>
>> JS-code:
>> window.datetimepicker1 = new tempusDominus.TempusDominus(
>>   document.getElementById('datetimepicker1'), { my-property: false } );
>
> Seems I missed this mail. So a late reply
>
> How I do this usually, using new:
>
> window.datetimepicker1 = new tempusDominus.TempusDominus(
>    document.getElementById('datetimepicker1'), 
> new(['my-property',false]));
>
> You can recurse:
> new([
>   'my-property',false,
>   'headers', new(
>       ['content-type','application/json',
>        'authorization','basic ABC'
>       ])
>    ]);
>
>
> The new() function exists in the JS unit.

Great, thank you Michael!

I couldn't find it myself and ended up with TJSTempusDominusOptions = 
class external name 'Object'(TJSObject). Now I can make it simpler.

Ondrej



More information about the Pas2js mailing list