gpt4 book ai didi

sproutcore - 在 Sproutcore 2 中编写自定义控件

转载 作者:行者123 更新时间:2023-12-02 15:22:00 25 4
gpt4 key购买 nike

我对 Sproutcore 还很陌生,但我对 Handlebars 很熟悉。我已经完成了 Todo 教程并检查了一些其他示例。

我喜欢它的一切,并且想在 Backbone 上使用它,但我很难理解如何连接自定义控件。我可以看到一些数据将在绑定(bind)中发挥作用,但我会迷失在触发事件中。

举个例子,如果我有一个链接列表,我想用它来过滤它下面的数据,我该如何绑定(bind)到事件?我知道在主干中你会使用事件和选择器:“click .link”

任何帮助将不胜感激!

最佳答案

听起来您想要循环遍历对象列表并创建链接,单击该链接时,会调用一些有权访问原始对象的 JavaScript 代码。

目前,最简单的方法是将模板上下文绑定(bind)到新的自定义 View 。您可以在此 JSFiddle 中看到所有操作:http://jsfiddle.net/67GQb/

模板:

{{#each App.people}}
{{#view App.PersonView contentBinding="this"}}
<a href="#">{{content.fullName}}</a>
{{/view}}
{{/each}}

应用程序代码:

App = SC.Application.create();

App.Person = SC.Object.extend({
fullName: function() {
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastName')
});

App.people = [
App.Person.create({ firstName: "Yehuda", lastName: "Katz" }),
App.Person.create({ firstName: "Tom", lastName: "Dale" })
];

App.PersonView = SC.View.extend({
mouseDown: function() {
// Note that content is bound to the current template
// context in the template above.
var person = this.get('content');
alert(person.get('firstName'));
}
});

也就是说,我们知道这有点麻烦,并且有一些进一步简化流程的想法,我们将在未来几周内开展工作。

关于sproutcore - 在 Sproutcore 2 中编写自定义控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7174487/

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