Che*_*het 8 javascript events templates meteor
我想用来template.find
让我的生活更轻松.
但是在javascript控制台中,我得到: undefined is not a function
这就是我所拥有的.它正在被绊倒template.find(...)
Template.superuserHUD.events =
{
'click input.new_device': function (template) {
var id = template.find(".new_device_id").value;
Device_IPs.insert({ID: id, IP: "Not Connected"});
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
soh*_*ifa 16
事件处理程序函数接收两个参数:event
一个包含事件信息的对象,以及template
定义处理程序的模板的模板实例.
第二个参数是可选的,但它需要在处理程序接收时要使用像模板实例功能find()
,findAll()
,firstNode()
和lastNode()
.
因此,要template.find()
在事件处理程序中使用,您需要将两个参数都传递为:
'click input.new_device': function (event, template) {
// your event handling code
}
Run Code Online (Sandbox Code Playgroud)
请使用第二个安慰
Template.superuserHUD.events
'click input.new_device': (event, template) ->
options =
id: template.find('.new_device_id').value
IP: 'Not Connected'
Device_IPs.insert options
Run Code Online (Sandbox Code Playgroud)
有时使用模板本身
Template.superuserHUD.events
event: (event, template) ->
@find('.new_device_id').value
Run Code Online (Sandbox Code Playgroud)
这里的咖啡文盲的javascript也一样......
Template.superuserHUD.events({
'click input.new_device': function(event, template) {
var options;
options = {
id: template.find('.new_device_id').value,
IP: 'Not Connected'
};
return Device_IPs.insert(options);
}
});
Run Code Online (Sandbox Code Playgroud)
Template.superuserHUD.events({
event: function(event, template) {
return this.find('.new_device_id').value;
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7082 次 |
最近记录: |