I have a view model something like below, when onAfterRender is fired by Knockout then the function in the viewmodel (also called onAfterRender) is executed but the values for this.gridColumns, this.gridOptions are undefined is there anyway to fix this? I would prefere to keep the object function rather than using an object literal.
I create my viewModel like this:
var model = new i2owater.viewmodels.AlarmsForViewModel(somedata);
and call ko.applyBindings(model);
this is my view model:
viewModel = function (serverData) {
var alarmGrid = {};
function onAfterRender() {
var that = this;
this.alarmGrid = new i2owater.Slickgrid();
// this.gridColumns and this.gridOptions are both undefined
this.alarmGrid.setupGrid("#alarmsGrid", [], this.gridColumns, this.gridOptions);
};
return {
data: data,
tabs: tabs,
selectedPriority: selectedPriority,
company: company,
zone: zone,
rows: rows,
alarmPeriod: alarmPeriod,
//alarmGrid: alarmGrid,
gridColumns: [{ id: "id", name: "ID", field: "id", sortable: true },
{ id: "date", name: "Date", field: "date", sortable: true },
{ id: "description", name: "Description", field: "description"}],
gridOptions: {
editable: true,
enableCellNavigation: true,
asyncEditorLoading: true,
forceFitColumns: false,
topPanelHeight: 25,
rowHeight: 40
}
onAfterRender: onAfterRender
};
};