MeteorJSでCRUDアプリを書いています。さまざまな入力を含むhtmlフォームがあります。更新の場合、mongodbからのhtml入力のデフォルト値を設定できません。ケースの作成と更新で同じhtmlフォームを使用するにはどうすればよいですか?
ありがとう。
MeteorJSでCRUDアプリを書いています。さまざまな入力を含むhtmlフォームがあります。更新の場合、mongodbからのhtml入力のデフォルト値を設定できません。ケースの作成と更新で同じhtmlフォームを使用するにはどうすればよいですか?
ありがとう。
テンプレートでフォームを使用し、{{>template}}
別のフォームを使用して、イベントバインディングを分離することができます(meteorでフォームを実行している場合、それ以外の場合{{>form}}
は、JQueryを使用している場合に使用できます)。
クライアントHTML
<template name="form">
<form>
<input type="text" value="{{values.fieldname1}}"/>
</form>
</template>
<template name="crud">
<h1>Update</h1>
{{>update}}
<hr/>
<h1>New</h1>
{{>create}}
</template>
<template name="update">
{{>form}}
</template>
<template name="create">
{{>form}}
</template>
クライアントJs
Template.update.values = function() {
return MyCollection.findOne()
}
Template.update.events({
'submit':function(event,context) {
//update your stuff (your data would be in context.data)
event.preventDefault()
}
});
Template.create.events({
'submit':function(event,context) {
//create your new item
event.preventDefault();
}
});