Learner
Learner

Reputation: 2339

How to pass list in JavaScript?

I am trying to dynamically send a list object (as below) in JavaScript.

I am trying to setup a dynamic grid which accepts dynamic column names (instead of hardcoding the columns)

I am trying to create columnmap dynamically that will be used by grid, something like below,

columMap : {
    'Header' : [
        { title : "Title", field : "Title" },
        { title : "Created", field : "Created" },
        { title : "Created By", field : "CreatedBy.Account" }
    ]

I tried with var list={field : 'Name',title:'Name'}.. This works fine for one column but does't work for multiple columns. I tried array too, didn't work.. Anyone has any suggestions?

Upvotes: 0

Views: 571

Answers (2)

Learner
Learner

Reputation: 2339

Sorry, it was my mistake... I forgot to remove [] when I was passing my list object hence it was not able to set the value..

I got it resolved by passing list as below..

var list = [{ field: 'Name',title: 'Name' },{ field:'ContextNamePathRaw',title: 'Ownership Hierarchy'} ];

Thanks for your help!!!

BB

Upvotes: 0

BrunoLM
BrunoLM

Reputation: 100322

[] represents an empty array

[1, 2, 3] is an array of three numbers

[ { a: 1 }, { a: 1 } ] is an array of objects

[ 1, "a", { a: 3 } ] an array does not care what type it holds

So...

var list = 
[
    {field : 'Name',title:'Name'}
];

Upvotes: 3

Related Questions