如何使用typescript定义emberjs观察者和计算属性?
我需要用typescript编写以下代码。
module App {
App.UserController = ember.ObjectController.extend({
firstName: "John",
lastName: "Doe",
fullName: function() {
return this.get("firstName") + " " + this.get("lastName");
}.property("firstName", "lastName")
});
}类似于:
class UserController extends ember.ObjectController {
firstName: string;
lastName: string;
constructor() {
super();
this.firstName = "John";
this.lastName = "Doe";
}
get fullName(): string {
return this.firstName + " " + this.lastName;
}.property("firstName", "lastName")
}但这似乎并不管用。有人能告诉我不使用javascript的正确方法吗?
发布于 2015-01-26 19:05:23
以下是将编译的代码的一个版本:
module App {
export var UserController = Ember.ObjectController.extend({
firstName: "John",
lastName: "Doe",
fullName: function () {
return this.get("firstName") + " " + this.get("lastName");
}.property('model.isCompleted')
});
}
// Example:
var x = App.UserController;更新
你可以用一个类来实现它,下面是一个编译的例子:
class UserController extends Ember.ObjectController {
private firstName: string;
private lastName: string;
constructor() {
super();
this.firstName = "John";
this.lastName = "Doe";
}
get fullName(): string {
return this.firstName + " " + this.lastName;
}
}
var x = new UserController();
console.log(JSON.stringify(x));https://stackoverflow.com/questions/28147145
复制相似问题