1

I have a multiselect combobox in my extJS form.

It returns an array of strings on submit.

I want to convert it the array to json(in a particular format).

Eg. It returns in the following array:

categories : ['ABC','XYZ']

I want the JSON in the following format:

"categories":[{"name":"ABC"},{"name":"XYZ"}]

Are there any methods in ExtJs to do this? How to achieve this using javascript?

2 Answers 2

2

You can use the Array.map method in vanilla JS:

var out = JSON.stringify(categories.map(function (el) {
  return { name: el };
}));

Output

[{"name":"ABC"},{"name":"XYZ"}]

Demo

Sign up to request clarification or add additional context in comments.

Comments

1

Why not use

selected = [];
Ext.each(categories, function (item) {

   selected.push({
          'name': item
   });
});

Ext.encode(selected)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.