[英]How to add a submit button in Meteor.js?
Template.feed.events = ({
// Press enter to submit the post.
'keypress, .posttext':function(evt,tmpl){
if(evt.which == 13){
var posttext = tmpl.find('.posttext').value;
var options = {text:posttext,parent:null};
Meteor.call('addPost',options);
$('.posttext').val("").select().focus();
}
}
I am not so good with Meteor or javascript, are there any good resources that will break down Meteor into a basic understanding? 我对Meteor或javascript不太满意,是否有任何好的资源可以将Meteor分解为基本知识? Thanks!
谢谢!
Here's the correct way of handling a submit button: 这是处理提交按钮的正确方法:
// client/yourtemplate.html
<template name="yourForm">
<form>
<input type="text" class="posttext">
<input type="submit" value="Submit post">
</form>
</template>
// client/yourfile.js
Template.feed.events = {
// "submit form" handles all types of form submission: pressing Enter in
// the input text field, clicking the button, or tabbing to it then
// pressing Enter
'submit form': function (event, template) {
event.preventDefault(); // disable the browser's form submission
var posttext = template.find('.posttext').value;
...
}
};
Note that in the low-level keypress
approach, you had an extra comma between keypress
and .posttext
. 请注意,在低级
keypress
方法中, keypress
和.posttext
之间有一个逗号。 The even selector syntax is eventtype selector
, and commas separate different selectors . 偶数选择器语法是
eventtype selector
, 逗号分隔不同的选择器 。
That said, welcome to Meteor! 也就是说,欢迎来到流星! A few pointers:
一些提示:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.