我正在使用来自 Knockout.JS 站点 ( http://jsfiddle.net/rniemeyer/QSRBR/ ) 的分页网格示例来构建网格。我在网格模板中声明了一个点击事件,如下所示(点击:goBackward):-
templateEngine.addTemplate("ko_negrid_navigation", "\
<div class=\"ko-grid-pageLinks\">\
<br/>\
<span><img src=\"/OCSENET/images/bluLeftNew.gif\" style=\"cursor:hand;\" alt=\"Backward\" data-bind='click: goBackward, visible: shouldShowBack' /></span>\
<span> </span>\
<span><img src=\"/OCSENET/images/bluRightNew.gif\" style=\"cursor:hand;\" alt=\"Forward\" data-bind='click: goForward, visible: shouldShowFwd' /></span>\
</div>");
现在我需要在调用此 Grid ViewModel 的 ViewModel 中定义此 goBackward 方法,而不是在此 Grid View Model 自身中定义此方法。当我这样做时,事件不会触发 goBackward()。我正在从另一个 TestViewModel 调用网格,如下所示:
/*----------------------------------------------------------------------*/
/* TEST View Model
/*----------------------------------------------------------------------*/
function TESTViewModel() {
var self = this;
self.iRowFrom = ko.observable(1);
self.iRowTo = ko.observable(5);
self.gridRowCount = ko.observable(5);
self.VM_AHISGrid;
self.GridItems = ko.observableArray([]);
//fnDesignGrid
self.fnDesignGrid = function () {
self.VM_AHISGrid = new ko.NEGrid.viewModel({
data: self.GridItems,
columns: [
{ headerText: "Address", rowText: "AHIS_Address" },
{ headerText: "City", rowText: "AHIS_Addr_City" },
{ headerText: "State", rowText: "AHIS_Addr_State" },
{ headerText: "Zip", rowText: "AHIS_Addr_Zip" }
],
pageSize: self.gridRowCount(),
gridName: 'ALST_NE_GRID'
});
}
// I want this method to be triggered.
self.goBackward = function () {
alert('I m Backward')
};
}