找回密码
 立即注册

QQ登录

只需一步,快速开始

HHJ1983

注册会员

7

主题

17

帖子

60

积分

注册会员

积分
60
HHJ1983
注册会员   /  发表于:2017-11-18 13:34  /   查看:3344  /  回复:3
本帖最后由 HHJ1983 于 2017-11-18 13:36 编辑

Spread sheet 自定义单元格类型出错,麻烦懂的人指点一下是什么情况,谢谢

代码如下:

  1. //define BindingPathCellType   
  2.     function BindingPathCellType():void{
  3.       GC.Spread.Sheets.CellTypes.Text.call(this);
  4.     }
  5.     BindingPathCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  6.     BindingPathCellType.prototype.paint = function(ctx:CanvasRenderingContext2D, value:string, x:number, y:number, w:number, h:number, style : any, context : any){
  7.       if (value === null || value === undefined) {
  8.         var sheet = context.sheet, row = context.row, col = context.col;
  9.         if (sheet && (row === 0 || !!row) && (col === 0 || !!col)) {
  10.           var bindingPath = sheet.getBindingPath(context.row, context.col);
  11.           if (bindingPath) {
  12.             value = "[" + bindingPath + "]";
  13.           }
  14.         }
  15.       }
  16.       GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  17.     };

  18.    
  19.     var bindingPathCellType = new BindingPathCellType();
复制代码


代码是typescript,不是javascript,红色部分提示错误:

[ts] 其目标缺少构造签名的 "new" 表达式隐式具有 "any" 类型。
(local function) BindingPathCellType(): void


如下图:

未命名-1.jpg

3 个回复

倒序浏览
Clark.Pan讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2017-11-20 14:40:46
沙发
您好:

自定义方法应该定义到类的层级中,而不是类中的方法中
定义一个类像这样:
class BindingPathCellType extends GC.Spread.Sheets.CellTypes.Text{


        paint(ctx:CanvasRenderingContext2D, value:string, x:number, y:number, w:number, h:number, style : any, context : any){
                if (value === null || value === undefined) {
                    var sheet = context.sheet, row = context.row, col = context.col;
                    if (sheet && (row === 0 || !!row) && (col === 0 || !!col)) {
                      var bindingPath = sheet.getBindingPath(context.row, context.col);
                      if (bindingPath) {
                        value = "[" + bindingPath + "]";
                      }
                    }
                }
                GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
        }
};
引用时还是想之前方法那样new对象来引用。
以下地址博客可以供您参考:
http://blog.gcpowertools.com.cn/post/ColorPickerByTypeScript.aspx
博客图中的写法您可以进行参考
回复 使用道具 举报
HHJ1983
注册会员   /  发表于:2017-11-20 16:18:04
板凳
ClarkPan 发表于 2017-11-20 14:40
您好:

自定义方法应该定义到类的层级中,而不是类中的方法中

非常感谢,按照你的方式,问题已解决。
回复 使用道具 举报
Clark.Pan讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2017-11-20 17:18:58
地板
好的,那就结帖了。有什么问题欢迎另开新帖进行询问。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部