For beter work with Collections (key, label, value) - supports sorting
Link to blog: Design Studio SDK: Collection Util Component
Name | Description | Group | Default | Visible |
---|
Name | Description | Group | Default | Visible |
---|
Name | Parameters | Return |
---|---|---|
addItem [details] | key, label, value, (prop1), (prop2), (prop3) | void |
fillIntoSelectionComponent [details] | selectionComponent, (maxMembers) | void |
getAsKeyLabelValueArray [details] | (maxMembers) | org.scn.community.shared.KeyLabelValueArray |
getAsKeyLabelValuePropertyArray [details] | (maxMembers) | org.scn.community.shared.KeyLabelValuePropertyArray |
getCollectionAsJSON [details] | String | |
getEntryByKey [details] | key | org.scn.community.shared.KeyLabelValueProperty |
getIndexByKey [details] | key | int |
getKeyByIndex [details] | index | String |
getKeys [details] | (separator) | String |
getLabelByIndex [details] | index | String |
getLabelByKey [details] | key | String |
getLabels [details] | (separator) | String |
getLength [details] | int | |
getValueByIndex [details] | index | float |
getValueByIndexAsString [details] | index | String |
getValueByKey [details] | key | float |
getValueByKeyAsString [details] | key | String |
getValues [details] | (separator) | String |
removeAllItems [details] | void | |
removeItem [details] | key | int |
setItems [details] | keys, labels, values, (separator), (prop1s), (prop2s), (prop3s) | void |
size [details] | int | |
sortByKey [details] | (direction) | void |
sortByKeyDescending [details] | void | |
sortByLabel [details] | (direction) | void |
sortByLabelDescending [details] | void | |
sortByValue [details] | (direction) | void |
sortByValueDescending [details] | void |
Name | Description | Group | Default | Visible |
---|---|---|---|---|
items [String] |
Technical proprty for list of items Technical proprty for list of items |
Display | false |
void addItem |
Adds a value to new or existing array. This implementation of collection allows duplicate keys. You want to create an "k1,k2,k3" array: COLLECTION_1.addItem("k1", "l1", 45.75); This array has now following elements with keys: k1,k2,k3COLLECTION_1.addItem("k2", "l2", 11.21); COLLECTION_1.addItem("k3", "l3", 85.439);
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); if(prop1 == undefined) { prop1 = ""; } if(prop2 == undefined) { prop2 = ""; } if(prop3 == undefined) { prop3 = ""; } var itemDef = { "key" : key, "label" : label, "value" : value, "prop1" : prop1, "prop2" : prop2, "prop3" : prop3 }; a.push(itemDef); this.items = JSON.stringify(a); |
||||||||||||||||||||||||
void fillIntoSelectionComponent |
Fills the content of this array into given selection component You want to fill the dropdown with the content COLLECTION.fillIntoSelectionComponent(DROPDOWN, 30); Now the dropdown is filled in with given values
|
||||||||||||||||||||||||
Source Code |
selectionComponent.removeAllItems(); var that = this; var l = {}; l.list = this.getAsKeyLabelValueArray(maxMembers); if(this.isDebug()) { DEBUG.inspectZtl(that, l)}; for(var i=0;i<l.list.length;i++){ //erase '\"' to prettify titles/keys since json strings usually come with '"' var replacer = new RegExp('"','g'); var label = l.list[i].label; var key = l.list[i].key; label = label.replace(replacer,''); key = key.replace(replacer,''); selectionComponent.addItem(key, label); } if(this.isDebug()) { DEBUG.inspectZtl(that, l)}; |
||||||||||||||||||||||||
org.scn.community.shared.KeyLabelValueArray getAsKeyLabelValueArray |
Returns the collection content as loopable array. You want to loop at the "k1;k2;k3", "l1;l2;l3", "12.4;25.1;94.2" collection: var content = COLLECTION_1.getAsKeyLabelValueArray(); This LISTBOX_1 has now following values entries:// a loop for all entries content.forEach(function(element, index) { LISTBOX_1.addItem(element.key, element.label + "( " + element.value + " )"); });
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var tempA = []; // APPLICATION.createInfoMessage("Max: " + maxMembers); // debug if(maxMembers == undefined || maxMembers <= 0 || maxMembers > a.length) { maxMembers = a.length; } for(var i=0;i<maxMembers;i++){ var itemDef = { "key": a[i].key, "label": a[i].label, "value": a[i].value }; tempA.push(itemDef); } return tempA; |
||||||||||||||||||||||||
org.scn.community.shared.KeyLabelValuePropertyArray getAsKeyLabelValuePropertyArray |
Returns the collection content as loopable array. You want to loop at the "k1;k2;k3", "l1;l2;l3", "12.4;25.1;94.2" collection: var content = COLLECTION_1.getAsKeyLabelValueArray(); This LISTBOX_1 has now following values entries:// a loop for all entries content.forEach(function(element, index) { LISTBOX_1.addItem(element.key, element.label + "( " + element.value + " )"); });
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var tempA = []; // APPLICATION.createInfoMessage("Max: " + maxMembers); // debug if(maxMembers == undefined || maxMembers <= 0 || maxMembers > a.length) { maxMembers = a.length; } for(var i=0;i<maxMembers;i++){ var itemDef = { "key": a[i].key, "label": a[i].label, "value": a[i].value, "prop1": a[i].prop1, "prop2": a[i].prop2, "prop3": a[i].prop3 }; tempA.push(itemDef); } return tempA; |
||||||||||||||||||||||||
String getCollectionAsJSON |
Gets Collection As JSON String |
||||||||||||||||||||||||
Source Code |
//erase '\"' to prettify titles/keys since json strings usually come with '"' var result = this.items.replace(/\\"/g,''); var jsonObject = JSON.parse(result); return JSON.stringify(jsonObject, null, 4); |
||||||||||||||||||||||||
org.scn.community.shared.KeyLabelValueProperty getEntryByKey |
Returns the entry by given key. In case the key does not exist, key "N/A" is given back. You have a "k1,k2,k3" collection with value "Value for Key 2" at index 1 (key == "k2") and want to get the entry at key "k2": var entry = COLLECTION_1.getEntryByKey("k2"); Now "entry" is set to the entry "k2".var key = entry.key; var label = entry.key; var label = entry.label; var value = entry.value; var prop1 = entry.prop2; var prop2 = entry.prop2; var prop3 = entry.prop3;
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var r = { "key" : "N/A", "label" : "", "value" : "", "prop1" : "", "prop2" : "", "prop3" : "" }; for(var i=0;i<a.length;i++){ if(a[i].key == key) { r = a[i]; break; } } return r; |
||||||||||||||||||||||||
int getIndexByKey |
Returns index by given key. In case the key does not exist, "N/A" is given back. You have a "k1,k2,k3" collection with value "Value for Key 2" at index 1 (key == "k2") and want to get index at key "k2": var index1 = COLLECTION_1.getIndexByKey("k2"); Now "index1" is set to float "1".
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var r = "N/A"; for(var i=0;i<a.length;i++){ if(a[i].key == key) { r = i; break; } } return r; |
||||||||||||||||||||||||
String getKeyByIndex |
Returns key by given index. Indices are 0-based. In case the index does not exist, "N/A" is given back. You have a "k1,k2,k3" collection with label "Value for Key 2" at index 1 and want to get value at index 1: var key1 = COLLECTION_1.getKeyByIndex(1); Now "key1" is set to String "Value for Key 2".
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var r = "N/A"; if(a.length>index){ r = a[index].key; } return r; |
||||||||||||||||||||||||
String getKeys |
Returns all keys as String separated by given optional separator. default separator is comma , You have an array with 3 elements with keys ["K1", "K2", "K3"]: var keysAsString = COLLECTION_1.getKeys ("|"); The "keysAsString" has now "K1|K2|K3" as content.
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var tempA = []; for(var i=0;i<a.length;i++){ tempA.push(a[i].key); } if(separator == undefined) { separator = ","; } return tempA.join(separator); |
||||||||||||||||||||||||
String getLabelByIndex |
Returns label by given index. Indices are 0-based. In case the index does not exist, "N/A" is given back. You have a "k1,k2,k3" collection with label "Value for Key 2" at index 1 and want to get value at index 1: var label1 = COLLECTION_1.getLabelByIndex(1); Now "label1" is set to String "Value for Key 2".
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var r = "N/A"; if(a.length>index){ r = a[index].label; } return r; |
||||||||||||||||||||||||
String getLabelByKey |
Returns label by given key. In case the key does not exist, "N/A" is given back. You have a "k1,k2,k3" collection with value "Value for Key 2" at index 1 (key == "k2") and want to get value at key "k2": var label1 = COLLECTION_1.getLabelByKey("k2"); Now "label1" is set to float "Value for Key 2".
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var r = "N/A"; for(var i=0;i<a.length;i++){ if(a[i].key == key) { r = a[i].label; break; } } return r; |
||||||||||||||||||||||||
String getLabels |
Returns all labels as String separated by given optional separator. default separator is comma , You have an array with 3 elements with labels ["L1", "L2", "L3"]: var labelsAsString = COLLECTION_1.getLabels ("|"); The "labelsAsString" has now "L1|L2|L3" as content.
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var tempA = []; for(var i=0;i<a.length;i++){ tempA.push(a[i].label); } if(separator == undefined) { separator = ","; } return tempA.join(separator); |
||||||||||||||||||||||||
int getLength |
Returns length of current collection |
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); return a.length; |
||||||||||||||||||||||||
float getValueByIndex |
Returns value by given index. Indices are 0-based. In case the index does not exist, "0.0" is given back. You have a "k1,k2,k3" collection with value "54.48" at index 1 and want to get value at index 1: var value1 = COLLECTION_1.getValueByIndex(1); Now "value1" is set to float "54.48".
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var r = 0.0; if(a.length>index){ r = a[index].value; } return r; |
||||||||||||||||||||||||
String getValueByIndexAsString |
Returns value by given index. Indices are 0-based. In case the index does not exist, "NaN" is given back. You have a "k1,k2,k3" collection with value "54.48" at index 1 and want to get value at index 1: var value1 = COLLECTION_1.getValueByIndexAsString(1); Now "value1" is set to String "54.48".
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var r = "NaN"; if(a.length>index){ r = a[index].value; } return r; |
||||||||||||||||||||||||
float getValueByKey |
Returns value by given key. In case the index does not exist, "0.0" is given back. You have a "k1,k2,k3" collection with value "54.48" at index 1 (key == "k2") and want to get value at key "k2": var value1 = COLLECTION_1.getValueByKey("k2"); Now "value1" is set to float "54.48".
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var r = 0.0; for(var i=0;i<a.length;i++){ if(a[i].key == key) { r = a[i].value; break; } } return r; |
||||||||||||||||||||||||
String getValueByKeyAsString |
Returns value by given key. In case the index does not exist, "NaN" is given back. You have a "k1,k2,k3" collection with value "54.48" at index 1 (key == "k2") and want to get value at key "k2": var value1 = COLLECTION_1.getValueByKeyAsString("k2"); Now "value1" is set to String "54.48".
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var r = "NaN"; for(var i=0;i<a.length;i++){ if(a[i].key == key) { r = a[i].value; break; } } return r; |
||||||||||||||||||||||||
String getValues |
Returns all values as String separated by given optional separator. default separator is comma , You have an array with 3 elements with values ["11.4", "87.66", "147.41"]: var valuesAsString = COLLECTION_1.getValues ("|"); The "valuesAsString" has now "11.4|87.66|147.41" as content.
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var tempA = []; for(var i=0;i<a.length;i++){ tempA.push(a[i].value); } if(separator == undefined) { separator = ","; } return tempA.join(separator); |
||||||||||||||||||||||||
void removeAllItems |
Removes all Items (clears the collection) |
||||||||||||||||||||||||
Source Code |
var a = []; this.items = JSON.stringify(a); |
||||||||||||||||||||||||
int removeItem |
Removes an item from existing collection. This implementation of collection allows duplicate keys - all keys will be removed. You have an array with keys "k1,k2,k3": ARRAY_1.removeItem("k1"); This array has now following values: k2,k3Return is the number of removed items. 0 means no removal was done.
|
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); var newArray = []; var foundNumber = 0; for(var aI in a){ if(a[aI].key == key) { foundNumber++; } else { newArray.push(a[aI]); } } this.items = JSON.stringify(newArray); return foundNumber; |
||||||||||||||||||||||||
void setItems |
Sets items of the array by 2 strings: for keys, labels, values. Optionally a given separator can be specified. This implementation of collection allows duplicate keys. Values must be float numbers. The content length is equal with number of keys. in case labels or values are shorter, correspondingly an empty label or 0.0 will be inserted. You want to set the string "k1;k2;k3" array: COLLECTION_1.setItems("k1;k2;k3", "l1;l2;l3", "12.4;25.1;94.2", ";"); This array has now following values: k1,k2,k3
|
||||||||||||||||||||||||
Source Code |
var a = []; if(separator == undefined) { separator = ","; } if(prop1s == undefined) { prop1s = ""; } if(prop2s == undefined) { prop2s = ""; } if(prop3s == undefined) { prop3s = ""; } var k = keys.split(separator); var l = labels.split(separator); var v = values.split(separator); var p1 = prop1s.split(separator); var p2 = prop2s.split(separator); var p3 = prop3s.split(separator); while(k.length>l.length) l.push(""); while(k.length>v.length) v.push("0"); while(k.length>p1.length) p1.push(""); while(k.length>p2.length) p2.push(""); while(k.length>p3.length) p3.push(""); for(var i=0; i<k.length; i++){ var itemDef = { "key" : k[i], "label" : l[i], "value" : v[i], "prop1": p1[i], "prop2": p2[i], "prop3": p3[i] }; a.push(itemDef); } this.items = JSON.stringify(a); |
||||||||||||||||||||||||
int size |
Returns the current size. You have a "k1,k2,k3" collection with value "54.48" at index 1 (key == "k2") and want to get the size: var size = COLLECTION_1.size(); Now "size" is set to integer "3". |
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); return a.length; |
||||||||||||||||||||||||
void sortByKey |
Sorts the collection by values with optional parameter for direction (ascending is default)
|
||||||||||||||||||||||||
Source Code |
if(direction == org_scn_community_shared_SortDirection.Descending) { this.sortByKeyDescending(); return; } var s = this.items; var a = []; if(s!="") a = JSON.parse(s); a.sort(function(p,m){ var A = p.key.toLowerCase(); var B = m.key.toLowerCase(); if (A < B){ return 1; }else if (A > B){ return -1; }else{ return 0; } }); this.items = JSON.stringify(a); |
||||||||||||||||||||||||
void sortByKeyDescending |
Sorts the collection by key (descending) |
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); a.sort(function(p,m){ var A = p.key.toLowerCase(); var B = m.key.toLowerCase(); if (A > B){ return 1; }else if (A < B){ return -1; }else{ return 0; } }); this.items = JSON.stringify(a); |
||||||||||||||||||||||||
void sortByLabel |
Sorts the collection by values with optional parameter for direction (ascending is default)
|
||||||||||||||||||||||||
Source Code |
if(direction == org_scn_community_shared_SortDirection.Descending) { this.sortByLabelDescending(); return; } var s = this.items; var a = []; if(s!="") a = JSON.parse(s); a.sort(function(p,m){ var A = p.label.toLowerCase(); var B = m.label.toLowerCase(); if (A < B){ return 1; }else if (A > B){ return -1; }else{ return 0; } }); this.items = JSON.stringify(a); |
||||||||||||||||||||||||
void sortByLabelDescending |
Sorts the collection by labels (descending) |
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); a.sort(function(p,m){ var A = p.label.toLowerCase(); var B = m.label.toLowerCase(); if (A > B){ return 1; }else if (A < B){ return -1; }else{ return 0; } }); this.items = JSON.stringify(a); |
||||||||||||||||||||||||
void sortByValue |
Sorts the collection by values with optional parameter for direction (ascending is default)
|
||||||||||||||||||||||||
Source Code |
if(direction == org_scn_community_shared_SortDirection.Descending) { this.sortByValueDescending(); return; } var s = this.items; var a = []; if(s!="") a = JSON.parse(s); a.sort(function(p,m){ var newA = parseFloat(p.value); var newB = parseFloat(m.value); return newB-newA; }); this.items = JSON.stringify(a); |
||||||||||||||||||||||||
void sortByValueDescending |
Sorts the collection by values (descending) |
||||||||||||||||||||||||
Source Code |
var s = this.items; var a = []; if(s!="") a = JSON.parse(s); a.sort(function(p,m){ var newA = parseFloat(p.value); var newB = parseFloat(m.value); return newA-newB; }); this.items = JSON.stringify(a); |
||||||||||||||||||||||||