我在Vanilla JS中有以下Ember View:
App.TextboxView = Ember.View.extend({
tagName: 'div',
classNames: ['custom-text-area__child custom-text-area--text'],
attributeBindings: ['contenteditable'],
isEditable: true,
typing: false,
didInsertElement: function() {
},
contenteditable: (function() {
return this.get('isEditable') ? 'true' : 'false';
}).property('isEditable')
)};
我试图在Typescript中实现所说的Ember View:
如何将 contenteditable 函数转换为使用Typescript?
到目前为止,我已经删除了以下课程:
export class TextboxView {
public tagName = 'div';
public classNames = ['custom-text-area__child custom-text-area--text'];
public atttributeBindings = ['contenteditable'];
public isEditable = true;
public typing = false;
constructor() {
var self = this;
}
}
这甚至可能吗?
答案 0 :(得分:3)
好像我正在养成回答自己问题的习惯......
以下实现按预期工作(我肯定尝试过这个但显然很快就认为它不起作用LOL):
export class customTextBox {
public tagName = 'div';
public classNames = ['custom-text-area__child custom-text-area--text'];
public attributeBindings = ['contenteditable'];
public isEditable = true;
public typing = false;
public contenteditable = (function () {
return this.get('isEditable') ? 'true' : 'false';
}).property('isEditable')
public keyUp = function(event) {
}
public keyDown = function(event) {
}
}