我在 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:
- Typescript 类导出函数
- Ember View 需要一个对象
- contenteditable 似乎是由于 Embers 约定(在其生命周期中的某个位置)而运行,并适本地设置了计算属性
如何将 contenteditable 函数转换为与 Typescript 一起使用?
到目前为止,我已经删除了以下类(class):
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;
}
}
这可能吗?
最佳答案
似乎我正在养成回答自己问题的习惯......
以下实现按预期工作(我确实尝试过这个,但显然太快了,无法假设它不起作用,哈哈):
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) {
}
}
关于javascript - 带有 Ember View 的 typescript ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36018188/