Javascript 无法在google apps脚本表中使用类方法
我有两个用typescript输入的文件,然后用.gs为google应用程序脚本编译。我有一类带有方法的助手函数,当我调用这个方法时:flatte_u,我收到一个错误Javascript 无法在google apps脚本表中使用类方法,javascript,typescript,google-apps-script,Javascript,Typescript,Google Apps Script,我有两个用typescript输入的文件,然后用.gs为google应用程序脚本编译。我有一类带有方法的助手函数,当我调用这个方法时:flatte_u,我收到一个错误 TypeError: Cannot find function flatten_ in object function Utils() {...}. 我试过: 1.使展平成为一种静态方法 2.使变平\静态特性 3.将“展平”声明为公共函数 都在班里,没有决心 backend.ts import { Utils } from '.
TypeError: Cannot find function flatten_ in object function Utils() {...}.
我试过:
1.使展平成为一种静态方法
2.使变平\静态特性
3.将“展平”声明为公共函数
都在班里,没有决心
backend.ts
import { Utils } from './utils/_';
function onOpen() {
const ui = SpreadsheetApp.getUi();
ui.createMenu('Tracker')
.addItem('JUMP To Record', 'Jump')
.addToUi();
}
function Jump() {
const ui = SpreadsheetApp.getUi();
const prompt = ui.prompt('Submit A Tracker ID');
/** Once the user clicks ok */
if(prompt.getSelectedButton() == ui.Button.OK) {
/** If the tracker id length is less than 1 */
if(prompt.getResponseText().length < 1) {
Browser.msgBox('Submit A Valid Tracker Id');
} else {
/** Begin timer and find the tracker id record */
console.time('Jump To Tracker Id Execution');
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Client');
const trackerRange = spreadsheet.getRange('1:1').getValues();
const trackerColumn = trackerRange[0].indexOf('Tracker ID') + 1;
const trackerIds = Utils.flatten_(spreadsheet.getRange(1, trackerColumn, spreadsheet.getLastRow(), 1).getValues());
const recordIndex = trackerIds.indexOf(prompt.getResponseText());
console.timeEnd('Submit A Valid Tracker Id');
/** End timer and check record results */
if(recordIndex == -1) {
Browser.msgBox('Record ['+ prompt.getResponseText() + '] Could Not Be Found')
} else {
spreadsheet.setActiveRange(spreadsheet.getRange(recordIndex + 1, trackerColumn));
}
}
}
}
汇编_
// Compiled using ts2gas 3.4.4 (TypeScript 3.5.3)
var exports = exports || {};
var module = module || { exports: exports };
var Utils = /** @class */ (function () {
function Utils() {
}
Utils.prototype.flatten_ = function (_) {
/** Combines array of arrays of objects into a singular array of objects */
return [].concat.apply([], _);
};
Utils.prototype.guidlist_ = function (_) {
var _this = this;
var z_ = _.map(function () { return [_this.guidcreate_()]; });
return z_;
};
Utils.prototype.guidcreate_ = function () {
var _ = function () { return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); };
return (_() + _() + "-" + _() + "-" + _() + "-" + _() + "-" + _() + _() + _());
};
return Utils;
}());
exports.Utils = Utils;
通过扩展我能够访问的类,我找到了答案
export class Utils {
iArray: Array<any>
constructor(_:Array<any>) {
this.iArray = _;
}
}
export class Flatten extends Utils {
exe(): any {
return [].concat.apply([], this.iArray);
}
}
// Compiled using ts2gas 3.4.4 (TypeScript 3.5.3)
var exports = exports || {};
var module = module || { exports: exports };
var Utils = /** @class */ (function () {
function Utils() {
}
Utils.prototype.flatten_ = function (_) {
/** Combines array of arrays of objects into a singular array of objects */
return [].concat.apply([], _);
};
Utils.prototype.guidlist_ = function (_) {
var _this = this;
var z_ = _.map(function () { return [_this.guidcreate_()]; });
return z_;
};
Utils.prototype.guidcreate_ = function () {
var _ = function () { return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); };
return (_() + _() + "-" + _() + "-" + _() + "-" + _() + "-" + _() + _() + _());
};
return Utils;
}());
exports.Utils = Utils;
export class Utils {
iArray: Array<any>
constructor(_:Array<any>) {
this.iArray = _;
}
}
export class Flatten extends Utils {
exe(): any {
return [].concat.apply([], this.iArray);
}
}
import { Flatten } from "./utils/_";
const trackerIds = new Flatten(spreadsheet.getRange(1, trackerColumn, spreadsheet.getLastRow(), 1).getValues()).exe();