Typescript木偶UI对象

Typescript木偶UI对象,typescript,marionette,Typescript,Marionette,我曾尝试在Typescript中实现一个木偶ItemView,并希望使用UI对象简化对UI元素的调用 我制作了以下示例来简化它: /// <reference path="scripts/typings/marionette/marionette.d.ts" /> interface settings { el: any template: Function } class myApp extends Marionette.ItemView<Backbone

我曾尝试在Typescript中实现一个木偶
ItemView
,并希望使用UI对象简化对UI元素的调用

我制作了以下示例来简化它:

/// <reference path="scripts/typings/marionette/marionette.d.ts" />

interface settings {
    el: any
    template: Function
}

class myApp extends Marionette.ItemView<Backbone.Model> {
    constructor(options: settings) {
        super(options);
    }

    ui = {
        hello: '.hello'
    }

    events() {
        return {
            'click @ui.hello': 'heyWorld'
        }
    }

    heyWorld() {
        console.log("Hey heyWorld!!!!");
    }
}

window.onload = () => {
    var app = new myApp({
        el: document.getElementById('content'),
        template: (data) => {
            return '<div class="hello"><p>Hej world - click me</p></div>';
        }
    });
    app.render();
};

以前有人碰到过这个问题吗?有没有人找到一种实现木偶UI对象的好方法,可以避免笨拙的获取/设置UI代码?

解决方案非常简单。只需传递带有选项对象的ui对象,如:

类myApp扩展了Marionette.ItemView{
构造函数(选项:主干.ViewOptions){
this.ui={
你好:“.你好”
}
超级(期权);
}
事件(){
返回{
'点击@ui.hello':'heyWorld'
}
}
海沃德(){
console.log(“HeyHeyWorld!!!!”);
}
}

这是否已经中断?原因ES6中super()之前不允许使用“this”。这让我们回到开始时的错误。尝试调用
super
作为构造函数中的内容。如果这不起作用,那么尝试将ui集成到传递给super的选项中,例如
options.ui={hello:'.hello'};超级(期权)
get ui() {
        return {
            hello: '.hello'
        }
    }

    set ui(value) { 
        // somehow marionette want to set this.ui to an empty object 
    }