Wilson Wu
Wilson Wu

Reputation: 121

Call function with variable array

The function works fine when calling like this.

                GenColumns({columns: [
                    { headerText: "ID"},
                    { headerText: "Doc"},
                    { headerText: "Customer ID"}
                ] }]

But if I change to this, it doesn’t work.

        var col = [{ headerText: " ID", key: "D"},
            { headerText: "Doc"},
            { headerText: "Customer ID"}
        ];

                GenColumns({columns: [
                    col
                ] })

How can I call function passing a generated string because “col” variable will be generated and does not type manually?

Thanks Wilson

Upvotes: 0

Views: 67

Answers (3)

edotassi
edotassi

Reputation: 476

var col = [{ headerText: " ID", key: "D"},
        { headerText: "Doc"},
        { headerText: "Customer ID"}
    ];

            GenColumns({columns: col})

Upvotes: 0

Satpal
Satpal

Reputation: 133403

Instead of

GenColumns({columns: [ col ] })

Use

GenColumns({columns: col})

As col is already an array you just need to pass it.

Upvotes: 1

SergeS
SergeS

Reputation: 11779

This code

        var col = [{ headerText: " ID", key: "D"},
            { headerText: "Doc"},
            { headerText: "Customer ID"}
        ];

                GenColumns({columns: [
                    col
                ] })

Is not the same as first one ... correct replacement is

        var col = [{ headerText: " ID", key: "D"},
            { headerText: "Doc"},
            { headerText: "Customer ID"}
        ];

                GenColumns({columns: col })

Because you duplicated the arrays. instead of columns : Array( Column ) you made columns : Array( Array( Column ))

Upvotes: 1

Related Questions