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
3 Answers 3
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 ))
answered Oct 2, 2013 at 7:44
SergeS
11.9k3 gold badges31 silver badges35 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Instead of
GenColumns({columns: [ col ] })
Use
GenColumns({columns: col})
As col is already an array you just need to pass it.
answered Oct 2, 2013 at 7:44
Satpal
134k13 gold badges168 silver badges171 bronze badges
Comments
var col = [{ headerText: " ID", key: "D"},
{ headerText: "Doc"},
{ headerText: "Customer ID"}
];
GenColumns({columns: col})
answered Oct 2, 2013 at 7:44
edotassi
4762 gold badges6 silver badges19 bronze badges
Comments
lang-js
GenColumns({columns: [col] })toGenColumns({columns: col }).colis already an array