Hi all,
Noticed that Array has a [‘Name’] property, so that you can access elements by name rather than by number.
How do I create my own array with named elements?
Hi all,
Noticed that Array has a [‘Name’] property, so that you can access elements by name rather than by number.
How do I create my own array with named elements?
var elementNameArray = new Array();
for (var i=0; i < form.xxxx.elements.lenght; i++)
{
elementNameArray = form.xxxx.elements*.getName();*
}
This is from the top of my head, but I think you will get the idea
Paul
Thanks Paul. Not quite what I was looking for…
Meanwhile I have discovered Javascript Objects.
You could do something like:
var t = new Object;
t.query = "SELECT name FROM people WHERE name like '%<input>%'";
t.datatype = 'String';
t.input= 'A';
This could be used to reduce the number of global variables and make the code easier to reuse.
Are JavaScript Objects supported in Servoy?
yes, without problems. But it should be var t = new Object();
read this one a bit tooooooo quick, I think…
Great. I’m trying to develop a HTML-based listview with sorting and searching.
At the moment I have to pass a lot of variables between the functions and rely and a number of global variables.
I’m hoping to reduce this to one global to hold a JavaScript object containg all the info I need to keep track of.
Then, when I reused the code on a different form, I only have to declare two new globals:
Servoy does not seem to like to pass these objects around :-(. I just spotted this thread:
Just had a couple of ideas to avoid using all these globals until Servoy comes up with something better:
a) Storing multiple values inside the same global using simple XML like tags:
1
25
etc,
b) Storing this info in the backend database. In my case, I would need one record per user per form. Not sure what overheads this would create… it would only be about 50 characters per for form/user…
Any thoughs anyone?
I’m not quite sure I follow exactly what you would like to do, but let me see:
1- You want to create 1 variable somwhow, containing multiple values
2- Acces this variable from different Forms/Methods, right?
Is this is the case, wouldn’t the following options work for you:
If that doesn’t work, have you tried putting the object in a runtime declared Global Variable?
Maybe I’m completely missing the point If so, never mind my yabbling…
Paul
pbakker:
I’m not quite sure I follow exactly what you would like to do, but let me see:1- You want to create 1 variable somwhow, containing multiple values
2- Acces this variable from different Forms/Methods, right?
In my case I would need one global variable per form. One is a lot better than 5…
pbakker:
Is this is the case, wouldn’t the following options work for you:
- Create your new Object() and fill it somehow
- Insert the object into a Global (predefined) Variable of Servoy?
Servoy 2.1.2 did not like this at all… I could not access the data.
pbakker:
If that doesn’t work, have you tried putting the object in a runtime declared Global Variable?
How do you declare a global at runtime and what is the scope of such a variable?
pbakker:
Maybe I’m completely missing the pointIf so, never mind my yabbling…
No, not at all. We may be attacking the problem in different ways, but we are both aiming for easy reuse of elements to save development time.
Declaring a global at runtime:
globals.xxxxx = yadayadayada
Where xxxxx is a name. Offcourse not a name of an existing Global variable (I would also not pick a name from a global method)
yadayadayada is the content of the new variable, for example, your new Object();
The scope of this global is solution wide, as long as the solution exists.
Paul