Repository navigation
UIParam Dictionary
SmartJSONEditor edited this page Aug 30, 2017
·
5 revisions
Dictionary parameter is suitable for Key / Value / enabled user values. User can freely create or remove several items.
Note, dictionary UI Parameter returns Array of objects, you should filter it by enabled value and create a key:value object that is suitable in other scripting inputs.
this.parameters = function () {
var dictionaryUIParameter = {
name: "myDictionaryParam",
type: "Dictionary",
displayName: "Dictionary Parameter",
description: "Press + button to create an item",
defaultValue: [{ key:"Key", value: "Value", enabled: true }],
userInfo: { keyPlaceholder: "Parameter Name", valuePlaceholder: "Parameter Value" }
};
return [dictionaryUIParameter];
}
this.environments = function (parameters, info) {
// returns [ { key: "Key", value: "value", enabled: true } ... ] values
var dictionaryArrayParameterValue = parameters.myDictionaryParam; // Array of objects
var keyValueDictionary = convertDictionaryParameter(dictionaryParameterValue); // Dictionary type object
};
// Returns { key : value } object
function convertDictionaryParameter(dictionary) {
// Dictionary UI parameter returns { key: "key", value: "value", enabled:true } elements in array.
// Filter not enabled and convert them to single key:value dictionary
if (dictionary === undefined) { return {} }
var keyValue = {};
for(var i=0; i< dictionary.length;i++) {
var item = dictionary[i];
if (item.enabled === true) { keyValue[item.key] = item.value; }
}
return keyValue;
}All UI parameters are Javascript Objects.
Name property identifies the parameter name and also returns the value in functions that receives the parameters input. Access the value using the parameters.name property.
Dictionary, set the type as "Dictionary"
Interface display name.
Interface detail text
Array of objects [ { key: "key", value: "value", enabled: true }, ...]