javascript - 带有 Ember View 的 typescript

标签 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 View 需要一个对象
  3. 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/

相关文章:

ember.js - 使用 DS.FixtureAdapter 时无法查询 Emberjs 模型

javascript - 解码后的 URI 在 HTML 中无法正确显示

angularjs - 单独的 REST 后端 API 的优点?

javascript - Node.js - 单线程,非阻塞?

javascript - FireFox 中未触发 Ember 操作

javascript - 如何使用 Angular 8 为某些回调(Leaflet 库)设置事件处理程序

javascript - 如何在 typescript 中的对象中使用类变量?

javascript - 如果总是以不同/随机名称返回,如何绑定(bind)到 json key ?

javascript - 我如何使用 angularjs 打印星形图案(我可以使用 ng-repeat)

javascript - 使 div 表现得像 iframe