problem with listbox - Forum

Forum Navigation
You need to log in to create posts and topics.

problem with listbox

I want to populate my LB from a database.

the subroutine getAnnee (below) populate my array, but after I have a loop with this error :

CreateEmptyArray [annees]
SetVar [annees] [resp]

----------

TypeError: str.indexOf is not a function
<anonymous> http://diapo/js/main.js:1
Angular 7
angular.min.js:129:202

----------

If I do not declare [annees] in Articles of the listbox I do not get error.

Uploaded files:
  • You need to login to have access to uploads.

@phil78 as [annees] is an Array you can not use SetVar directly.
You should loop all [resp] array items and use ArraAddItem instead.
Fot this to work you must be sure [resp] is a simple Array too.

Loop 0 [resp.length-1] [n]
   ArrayAddItem [annees] [resp([n])]
EndLoop

Regards.

thanks @luishp Really neoPhpExecSql send an array of object to the subroutine.

So I have tried with ArrayAddItem [annees] [resp([n]).annee] but [resp.length-1] is undefined...?

finally I use the code below which is Ok, but is this the only possibility ?

CreateEmptyArray [annees]
CreateEmptyObject [tempo]
SetVar [tempo] [resp]
Loop 0 [tempo.length-1] [i]
ArrayAddItem [annees] [tempo([i]).annee]
EndLoop

Regards.

@phil78 if you are using neoPhp your ariginal approach should work. Please check the attached image to see a complete working example code.

Regards.

Uploaded files:
  • You need to login to have access to uploads.

@luishp I agree with you. What I don't understand is why if I use directly the parameter [resp] it failed, but not if I copy the parameter to another variable.

@phil78 I know it's awful. Think on it as a temporal variable you can't use directly.