带有Ember视图的打字稿

时间:2016-03-15 17:30:34

标签: javascript ember.js typescript

我在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:

  1. Typescript类导出函数
  2. Ember Views期待一个对象
  3. contenteditable 似乎是由于Embers约定(在其生命周期中的某个地方)运行并正确设置计算属性
  4. 如何将 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; 
      }
    
    }
    

    这甚至可能吗?

1 个答案:

答案 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) {
    }
}