访问打字稿中的方法

时间:2017-09-08 15:11:52

标签: typescript datatable

我想在datatable类中调用getPopupWindowName方法。 问题出在datatable类上,页面是类型的,所以它不允许我调用getPopupWindowName方法。我是打字稿的新手,所以不知道它是如何完成的 我有一个页面如下

 import BasePage from '../BasePage';
import PageHeaderRight from '../PageHeaderRight';
import DataTable from '../shared/DataTable';
import DateCalendarInput from '../shared/DateCalendarInput';

 export default class FXOptionsPage extends BasePage {
  pageControls: PageHeaderRight<FXOptionsPage>;
  constructor() {
  super();
  this.pageControls = new PageHeaderRight<FXOptionsPage>(this);
 }
  startDate() {
   return new DateCalendarInput('mainform', 'a_von');
  }
 getDataTable(): DataTable<FXOptionsPage> {
 return new DataTable<FXOptionsPage>(this, 'TableData');
 }
 getPopupWindowName() {
 return 'OPgrafik';
  }
  }

我想在以下代码中访问getPopupWindowName

import ContractSecuritiesPage from '../TT/ContractSecuritiesPage';
import CreditLinesPage from '../TT/CreditLinesPage';
import FXOptionsPage from '../TT/FXOptionsPage';
import ChartPage from './ChartPage';
import ChartPopup from './ChartPopup';
import DataTableToolbar from './DataTableToolbar';
 import DetailsPopup from './DetailsPopup';
export default class DataTable<Page>  {
tableID: string;
 page: Page;

constructor(page: Page, tableID: string) {
this.tableID = tableID;
this.page = page;
 }
 clickDetailButton(): DetailsPopup<Page> {
 const buttonSelector = `tbody tr td`;
  this.getDataTableRootNode().element(buttonSelector).click();

  return new DetailsPopup(this.page, this.page.getDetailsPopupWindowName()(Here it say can't find methon on type page));
}

1 个答案:

答案 0 :(得分:0)

更改变量page的类型。

export default class DataTable<FXOptionsPage>  {
 page: FXOptionsPage;
 ...
}