gpt4 book ai didi

jquery - ToDo 应用程序无法正常工作

转载 作者:行者123 更新时间:2023-12-01 01:26:37 26 4
gpt4 key购买 nike

我试图编写一个 ToDo 应用程序,但我的复选框一开始就有问题......

http://jsfiddle.net/LRQyv/

模板:

<script type="text/x-handlebars">
{{view Todos.CreateTodoView id="new-todo" placeholder="What has to be done?"}}
{{#collection contentBinding="Todos.todosController" tagName="ul"}}
{{view Em.Checkbox titleBinding="content.title" valueBinding="content.isDone"}}
{{/collection}}
</script>​

代码:

window.Todos = Ember.Application.create();
Todos.initialize();

Todos.Todo = Ember.Object.extend({
title: null,
isDone: false
});

Todos.todosController = Ember.ArrayController.create({
content: [],
createTodo: function(title) {
var todo = Todos.Todo.create({title: title});
this.pushObject(todo);
}
});

Todos.CreateTodoView = Ember.TextField.extend({
insertNewline: function() {
var value = this.get('value');
if (value) {
Todos.todosController.createTodo(value);
this.set('value', '');
}
}
});​

..添加待办事项项时为什么没有添加标签,有什么想法吗?

最佳答案

您的代码中有两个问题,首先,您期望 Ember.Checkbox 允许 title 绑定(bind)。这是不可能的,如文档中所述:

You can add a label tag yourself in the template where the Ember.Checkbox is being used.

其次,你必须看看 Ember.js View Context changes 。您的绑定(bind)必须使用 {{view.content.title}}{{view.content.isDone}}

这是修改后的模板:

<script type="text/x-handlebars">
{{view Todos.CreateTodoView id="new-todo" placeholder="What has to be done?"}}
{{#collection contentBinding="Todos.todosController" tagName="ul"}}
<label>
{{view Em.Checkbox labelBinding="content.title" valueBinding="view.content.isDone"}}
{{view.content.title}}
</label>
{{/collection}}
</script>​

the associated JSFiddle .

关于jquery - ToDo 应用程序无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12458462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com