define an Array as @type{Array]

Questions, tips and tricks and techniques for scripting in Servoy

define an Array as @type{Array]

Postby Harjo » Fri Aug 19, 2011 9:44 am

HI there, I have a dataset.

Code: Select all
function addToArray(dataset) {
   var dataArray = dataset.getColumnAsArray(1)
   if (selections) {
      var a = selections.split(',')
      dataArray = dataArray.concat(a)
   }
}


but that gives me warning: The function concat() is undefined in this script
So I have to do this:

Code: Select all
function addToArray(dataset) {
   /**@type {Array} */
   var dataArray = dataset.getColumnAsArray(1)
   if (selections) {
      var a = selections.split(',')
      dataArray = dataArray.concat(a)
   }
}


Why do I have to add /**@type {Array} */ ?
Servoy does or can already know, that this is an Array??
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: define an Array as @type{Array]

Postby jcompagner » Fri Aug 19, 2011 3:50 pm

this works fine for me:

Code: Select all
/**
* @param {JSDataSet} dataset
*
* @properties={typeid:24,uuid:"055E25C1-5B73-4451-8948-C598E7EC95E9"}
*/
function addToArray(dataset) {
   var dataArray = dataset.getColumnAsArray(1)
   if (selections) {
      var a = selections.split(',')
      dataArray = dataArray.concat(a)
   }
}


i don't know if you did type dataset correctly as a param?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Methods

Who is online

Users browsing this forum: No registered users and 12 guests