JSDoc for associative array

Questions, tips and tricks and techniques for scripting in Servoy

JSDoc for associative array

Postby udiluca » Wed Apr 08, 2015 11:15 am

Hello,

I'm wondering how I could document an object/array whose properties holding common properties, which structure could be the following

var myVar = {};
myVar.aformname1= {};
myVar.aformname1.property1IsString= 'A';
myVar.aformname1.property2IsBoolean = true;
myVar.aformname1.property3IsObject= {};
myVar.aformname1.property4IsArrayOfString= [];
myVar.aformname1.property4IsArrayOfNumber= [];
myVar.aformname2= {};
myVar.aformname2.property1IsString= 'A';
myVar.aformname2.property2IsBoolean = true;
myVar.aformname2.property3IsObject= {};
myVar.aformname2.property4IsArrayOfString= [];
myVar.aformname2.property4IsArrayOfNumber= [];

So the 'aformname2' should be dynamic, and the rest are common properties associated

At the moment, my JSDoc works without the dynamic part of it, with a lot of expected reptitions that I'm sure I cas avoid, but I can't figure out how

@type{{
aformname1:{
property1IsString:String,
property2IsBoolean:Boolean,
property3IsObject:{};
property4IsArrayOfString:Array<String>,
property4IsArrayOfNumber:Array<Number>
},
aformname2:{
property1IsString:String,
property2IsBoolean:Boolean,
property3IsObject:{};
property4IsArrayOfString:Array<String>,
property4IsArrayOfNumber:Array<Number>
}
}}

Is there any way for this ?

Thanks

Ugo
udiluca
 
Posts: 24
Joined: Wed Apr 10, 2013 7:25 pm

Re: JSDoc for associative array

Postby udiluca » Wed Apr 08, 2015 11:44 am

Ok, never mind I solved it :

Here's one variation of it, just in case.
We use it to store foundsetFilterParams per form in a global variable in our solution. The basic remains the same :
In this case, we needed an object of type :

var storedFilterParams={};
storedFilterParams.aFormname.theFiltername= {};
storedFilterParams.aFormname.theFiltername.theTable= 'MyTable';
storedFilterParams.aFormname.theFiltername.theDataprovider= 'MyDataProvider';
etc.

@type {Array<Array<{theTable:String,theDataprovider:String,theOperator:String,theFilterValue:*}>>}
udiluca
 
Posts: 24
Joined: Wed Apr 10, 2013 7:25 pm

Re: JSDoc for associative array

Postby madimane » Wed Apr 08, 2015 12:43 pm

I'm not sure if that answers your question, but I'll do as follows.

Code: Select all
/**@type{{frmProperties:Array<{frmName:String,properties:{property1IsString:String,property2IsBoolean:Boolean,
       property3IsObject:{},
       property4IsArrayOfString:Array<String>,
       property4IsArrayOfNumber:Array<Number>}}>
      }
   }*/
   var myVar = {};
   /**@type {{frmName:String,properties:{property1IsString:String,property2IsBoolean:Boolean,
       property3IsObject:{},
       property4IsArrayOfString:Array<String>,
       property4IsArrayOfNumber:Array<Number>}}}*/
   var frm = new Object();
   
   myVar.frmProperties = new Array();
   frm.frmName = "aformname1";
   frm.properties.property1IsString = 'A';
   etc
   myVar.frmProperties.push(frm);
   frm = new Object();
   frm.frmName = "aformname2";
   frm.properties.property1IsString = 'A';
   myVar.frmProperties.push(frm);
Othmane himadi
Analyst / Developper
Freelancer
---------------------
Whether we want it or not, being a developer means documenting our code is a necessity
User avatar
madimane
 
Posts: 85
Joined: Tue Oct 13, 2009 5:16 am
Location: Montréal,QC,Canada


Return to Methods

Who is online

Users browsing this forum: No registered users and 9 guests

cron