#1 2018-08-27 22:36:29

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

VariantToTIntegerDynArray function

I have a TSQLRecord with a TIntegerDynArray field.
On mustache template a need call a custom Expression Helpers and use the TIntegerDynArray field as value, then on custom Expression Helpers I need extract the TIntegerDynArray value.

I cannot found a VariantToTIntegerDynArray function or something like this to use on custom Expression Helpers.

Offline

#2 2018-08-28 11:55:04

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,670
Website

Re: VariantToTIntegerDynArray function

Isn't the TSQLRecord serialized as a JSON array of integers?

Offline

#3 2018-08-28 22:26:48

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: VariantToTIntegerDynArray function

ab wrote:

Isn't the TSQLRecord serialized as a JSON array of integers?

It should be.

I have this TSQLRecord:

  TSQLProject = class(TSQLRecordTimeStamped)
  private
    fTitle: RawUTF8;
    fContacts: TIntegerDynArray;
    ...
  published
    property Title: RawUTF8 index 120 read fTitle write fTitle;
    property Contacts: TIntegerDynArray index 1 read fContacts write fContacts;
    ...
  end;

  TSQLContact = class(TSQLSomeone)
  private
    fBirthDate: TDateTime;
    fBirthPlace: RawUTF8;
    ...
  public

  published
    property BirthDate: TDateTime read fBirthDate write fBirthDate;
    property BirthPlace: RawUTF8 index 50 read fBirthPlace write fBirthPlace;
    ...
  end;

Then I need plot a mustache template using the Project data but also some contacts data (the same project can have more contacts).
On my idea I pass project data to mustache template then use Expression Helpers with Contacts value (array of integers) to get contacts data.

Is this the right approach? How deserialize the Json array?

Offline

#4 2018-08-28 23:16:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,670
Website

Re: VariantToTIntegerDynArray function

Use a Mustache loop over the array.

Please check the context data as JSON, and read again the docs about Mustache.
You don't need helpers here, I'm quite sure!

Offline

#5 2018-08-29 21:00:04

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: VariantToTIntegerDynArray function

ab wrote:

Use a Mustache loop over the array.

Please check the context data as JSON, and read again the docs about Mustache.
You don't need helpers here, I'm quite sure!

I cannot use a Mustache loop.
On Mustache template there is a Select2 input box (https://select2.org/). I need fill it with all contacts of my DB then select only contacts assigned to project.
To do it I thought to pass all array to Expression Helpers then use it for: 1. extract all contacts name from DB, 2. create all HTML about Select2 "option" and flag as "selected" the contact by TSQLProject.Contacts value.
To do it I need use array value on Expression Helpers but I cannot understand how handle array from variant.

Offline

#6 2018-08-30 12:15:53

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,670
Website

Re: VariantToTIntegerDynArray function

Using such an expression helper to query the DB is some kind of breaking of the whole Mustache concept... it should be done before apply the template, in the data context.
Anyway...

Use _Safe()^ then you can use for j := 0 to Count - 1 then VariantToInt64(Values[j])

Offline

#7 2018-08-30 13:01:09

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: VariantToTIntegerDynArray function

ab wrote:

Using such an expression helper to query the DB is some kind of breaking of the whole Mustache concept... it should be done before apply the template, in the data context.

So I should extract contacts before and send them with project data as json, right?

Offline

#8 2018-08-30 13:26:07

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,670
Website

Re: VariantToTIntegerDynArray function

Indeed.

Offline

Board footer

Powered by FluxBB