I seems to be not possible to use associative array as dataprovider for a Field in a Form ?
DisplayType CHECK:
- programmatically add a an associative array as dataprovider (globals.someField[‘fldname’]) wont work
- programmatically add a global variable (globals.someField) it works fine.
If this meant to be that way (maybe not ), i would created the global vars with
for (var i = 1; i <= maxCount; i++) {
oFld=solutionModel.cloneComponent('fld'+i,oFldMuster)
X = 'globals.tmp' + i + ' = ' + gArrChoi['l' + i] // example: "globals.tmp12 = true"
eval(X) // create the global var
oFld.dataProviderID = 'globals.tmp'+i
}
Is this the proper way, to create the globals with eval() ?
Is it neccessary because I can’t use the arrays as dataprovider ?
Thank you for any suggestions
Like you cannot do that when designing a form in Servoy Developer, you also cannot do that when building forms using the Solution Model.
Paul
pbakker:
Like you cannot do that when designing a form in Servoy Developer, you also cannot do that when building forms using the Solution Model.
Thank you Paul, good to know, that there is this rule, so I observe it in the future.
That means also, that I have to create on the fly a portion of global variables like:
globals.tmp1, globals.tmp2, globals.tmp3…
and my question was: Is this the proper way, to create the globals with eval() ?
I’m searching for something more elegant for
X = 'globals.tmp' + i + ' = true ' // "globals.tmp1 = true"
eval(X) // create the global var
greets
eval() == evil! Never use it, there are always better ways. Eval is a JavaScript design flaw. In the future versions of JavaScript is will not be available in the so-called strict mode, which was invented to block all wrong JavaScript usage.
There are two ways:
1: just do globals.xxxx = ‘something’ will dynamically add the global variable. I haven’t tested it, but I think those types of dynamically created global variables aren’t usable to link to elements as dataprovider through the solutionModel, because the solutionModel doesn’t know about it: it’s dynamically created at runtime.
2: call createGlobalVariable through the solution model to create the global variable, so it’s usable through the solutionModel as well.
Paul
pbakker:
eval() == evil! Never use it, there are always better ways.
Exactly, that’s why I asked for a propper way.
pbakker:
There are two ways:
1: just do globals.xxxx = ‘something’ will dynamically add the global variable. I haven’t tested it, but I think those types of dynamically created global variables aren’t usable to link to elements as dataprovider through the solutionModel, because the solutionModel doesn’t know about it: it’s dynamically created at runtime.
This is not what I’m searching for, because of the sequenced-number in the global var (globals.test1 globals.test2 globals.test3)
pbakker:
2: call createGlobalVariable through the solution model to create the global variable, so it’s usable through the solutionModel as well.
Paul
This is the goal ! I found (because of your suggestion) the solutionModel.newGlobalVariable() and at the same time I feel a shame to not
seeing it before.
Thank you Paul, a much help for me.
also you could use something like
globals[“tmp” +i] = avalue
to create a dynamic global value based on a counter (so tmp1,tmp2)
jcompagner:
globals[“tmp” +i] = avalue
to create a dynamic global value based on a counter (so tmp1,tmp2)
Thank you Johan, that’s it, what I’m searching for, instead of eval() in a loop !