var selectColumns = new Array();
selectColumns[0] = { TableName: "DeploymentRosterView", ColumnName: "ArrivedOn" };
selectColumns[1] = { TableName: "DeploymentRosterView", ColumnName: "DepartedOn" };
selectColumns[2] = { TableName: "DeploymentRosterView", ColumnName: "RoleType" };
selectColumns[3] = { TableName: "DeploymentRosterView", ColumnName: "AdjusterFirstName" };
selectColumns[4] = { TableName: "DeploymentRosterView", ColumnName: "AdjusterLastName" };
The above works to create my array in JavaScript, but is there a more graceful way to write the above? Like an Object Initializer? Just wondering
You can create it inline:
var selectColumns = [
{ TableName: "DeploymentRosterView", ColumnName: "ArrivedOn" },
{ TableName: "DeploymentRosterView", ColumnName: "DepartedOn" },
{ TableName: "DeploymentRosterView", ColumnName: "RoleType" },
{ TableName: "DeploymentRosterView", ColumnName: "AdjusterFirstName" },
{ TableName: "DeploymentRosterView", ColumnName: "AdjusterLastName" }];
You could restructure it like so:
var selectColumns = {
"DeploymentRosterView": {
"ColumnNames": ["DepartedOn", "RoleType", "AdjusterFirstName", "AdjusterLastName"]
}
};
// Loop through all views
for (view in selectColumns)
{
var v = selectColumns[view].ColumnNames;
alert('Column names for "' + view + '" is: ' + v.join(', '));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With