JS
Colors = new Meteor.Collection("colors");
Template.col_list.cols = function () {
return Colors.find();
};
Run Code Online (Sandbox Code Playgroud)
因此,此代码将输出从Col.find到html中的handlebar cols的所有内容
HTML
{{#each cols}}
{{name}}, {{RGB}}, {{HEX}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)
但是说我想要一个输入框,这样我就可以搜索颜色的名称,所以它只显示该颜色的信息或任何以我在输入框中键入的颜色开始的颜色.
示例:输入="bl"输出应为黑色,蓝色或以bl开头的任何其他内容.
在实践中,我一直在寻找任何这方面的例子,但我还没有找到.
到目前为止,我已经达到了这个效果,但它没有产生任何好运.
Template.col_list.events({
'click .search': function() {
Colors.find(name: $('col_name').val());
}
});
Run Code Online (Sandbox Code Playgroud)
您需要使模板的内容依赖于输入字段,以保持Meteor的反应性.会话变量非常适合.
这应该工作:
Colors = new Meteor.Collection("colors");
Template.col_list.cols = function () {
return Colors.find({name: { $regex: Session.get('prefix')+".*", $options: 'i' }});
};
Template.col_list.events({
'click .search': function() {
Session.set('prefix', $('.col_name').val());
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1926 次 |
最近记录: |