cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
841
Views
5
Helpful
4
Replies

Is it possible to create a new dynamic dictionary via Javascript?

esramasa
Cisco Employee
Cisco Employee

Is it possible to create a new dynamic dictionary via JavaScript ? Have a scenario in which need to create new fields to capture additional information based on the input selected by the user. Every time input varies and accordingly new dictionary fields should be generated

 

 

 

4 Replies 4

romaingautier
Level 1
Level 1

Hi,

It is not possible according to my knowledge of the tool service design methods...
To my mind the only means for your need is to define the additional fields statically, to hide them at the form loading, and to add conditional rules in order to display them dynamically.

The only "dynamical" possibility comes from datagrid which enable you to add several occurrences of sets of fields..
Rgds

 

Thanks Romaingauiter. Can we add fields to Dictionary  via some API?. In  my case defining static fields would lead to having many static fields(between 20 to 30) which is not a good design 

 

 

I have implemented services with more than 30 fields myself ;)

Perhaps you could investigate the creation of service items with the REST API and then add dictionary from them. But this process cannot be dynamical during the ordering of services...

Rgds

var dict = []; // create an empty array

dict.push({
    key:   "keyName",
    value: "the value"
});
// repeat this last part as needed to add more key/value pairs

Basically, you're creating an object literal with 2 properties (called key and value) and inserting it (using push()) into the array.

To be able to construct keys from strings, you'll need to set them accordingly:

var dictionary = {};
dictionary['[' + index + '].Key'] = $(this).attr('id');

Your currently overwriting the dictionary variable for each iteration. In your scenario, you'd want something like:

var dictionary = {};
$('.textClass').each(function (index) {
    dictionary['['+index+'].Key'] = $(this).attr('id');
    dictionary['['+index+'].Value'] = $(this).val();
});