Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. If you'd prefer to explore, try our test area to get started. And see here for current known issues.

Cisco Employee

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

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
New Member

Hi,It is not possible

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

 

Cisco Employee

Thanks Romaingauiter. Can we

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 

 

 

New Member

I have implemented services

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

New Member

<span class="kwd">var</span>

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();
});
82
Views
5
Helpful
4
Replies