我刚开始用Aurelia框架学习Typescript。我已经在Aurelia的Todo应用中实现了Matthew Davis的博客TypeScript Enums中的Aurelia模板使用ViewEngineHooks http://davismj.me/blog/template-constants/。打字稿枚举默认值
我希望将默认枚举值设置为列表中的第二个值,并将默认值设置为列表中的第一个值。
另外我想请想知道,如果{藤,优先级}或{只是}的Todo需要进口,如待办事项,list.ts显示
todo.ts
// Pro Tip: By starting our enum at 1, we ensure that all values in the enum are truthy.
export enum Priority {
High = 1,
Medium,
Low
}
export class Todo {
@observable done;
//*** Setting priority: Priority = 2 OR priority: Priority = Priority.Medium - Does not change the default from High/1 ***
//constructor(public list: TodoList, public description: string, public priority: Priority = 2, public editing: boolean = false) {
constructor(public list: TodoList, public description: string, public priority: Priority = Priority.Medium, public editing: boolean = false) {
this.list = list;
this.description = description;
//*** Setting this.priority = 2 OR this.priority = Priority.Medium - Does not change the default from High/1 ;
//this.priority = 2;
this.priority = Priority.Medium;
this.editing = false;
}
待办事项列表.TS
//*** Is {Todo} OR {Todo, Priority} needed for importing? ***
//import {Todo} from './todo';
import {Todo, Priority} from './todo';
...
add(description) {
if (description) {
//*** Setting (this, description, 2) OR (this, description, Priority.Medium) - Does not change the default from High/1 ***
//this.todos.push(new Todo(this, description, 2));
this.todos.push(new Todo(this, description, Priority.Medium));
this.invalidateView();
}
}
todo.html
<select id="priority" value.bind="type">
<option value.bind="Priority[type]" repeat.for="type of Prioritys">${type}</option>
</select>
在我的博客中有一个错字,感谢您帮我找到它 –