打字稿和 jqGrid
TypeScript and jqGrid
我正在尝试掌握 TypeScript,但在尝试访问 TS 代码中的 jqGrid 方法时遇到了问题;
我有以下代码;
/// <reference path="../scripts/typings/jquery/jquery.d.ts" />
/// <reference path="../scripts/typings/jqgrid/jqgrid.d.ts" />
interface IInvoice {
taxRate: number;
}
module mInvoice {
export class Invoice implements IInvoice {
constructor(public taxRate: number) { };
updateTotals(): void {
this.LinesTotal = $('#list').jqGrid('getCol', 'LineTotal', false, 'sum');
this.LinesGst = $('#list').jqGrid('getCol', 'LineGst', false, 'sum');
this.DiscountType =
.......
}
}
}
jqGrid sum
方法无法编译。
我已经包含了 jqGrid 的 /DefinitelyTyped *.d.ts
文件,这对 jQuery 工作正常。
*.d.ts
文件中是否缺少 jqGrid 方法定义?
是的,该 d.ts 文件中缺少接受 4 个参数的方法定义。
您可以通过创建自己的本地 jqGrid 来自行添加。d.ts 文件将用所需的方法声明补充现有定义,如下所示:
interface JQueryJqGridStatic
{
(gridName: string, id: any, param: boolean, method: string): any;
}
或者像这样,如果你希望与他们保持一致 docs:
interface JQueryJqGridStatic
{
(method: string, ...params: any[]): any;
}
希望对您有所帮助。
我正在尝试掌握 TypeScript,但在尝试访问 TS 代码中的 jqGrid 方法时遇到了问题;
我有以下代码;
/// <reference path="../scripts/typings/jquery/jquery.d.ts" />
/// <reference path="../scripts/typings/jqgrid/jqgrid.d.ts" />
interface IInvoice {
taxRate: number;
}
module mInvoice {
export class Invoice implements IInvoice {
constructor(public taxRate: number) { };
updateTotals(): void {
this.LinesTotal = $('#list').jqGrid('getCol', 'LineTotal', false, 'sum');
this.LinesGst = $('#list').jqGrid('getCol', 'LineGst', false, 'sum');
this.DiscountType =
.......
}
}
}
jqGrid sum
方法无法编译。
我已经包含了 jqGrid 的 /DefinitelyTyped *.d.ts
文件,这对 jQuery 工作正常。
*.d.ts
文件中是否缺少 jqGrid 方法定义?
是的,该 d.ts 文件中缺少接受 4 个参数的方法定义。
您可以通过创建自己的本地 jqGrid 来自行添加。d.ts 文件将用所需的方法声明补充现有定义,如下所示:
interface JQueryJqGridStatic
{
(gridName: string, id: any, param: boolean, method: string): any;
}
或者像这样,如果你希望与他们保持一致 docs:
interface JQueryJqGridStatic
{
(method: string, ...params: any[]): any;
}
希望对您有所帮助。