双击以编辑Meteor应用程序中的元素
Double click to edit element in Meteor app
我正在Meteor.js
为一家医院做一个学校项目——该应用程序的原型已经上线http://lrh.meteor.com。在表中的"查看医生"部分,我想双击记录并能够编辑Name
和email id
,但同时我也想更新MongoDB
集合中的记录。关于如何实现此功能,有什么想法吗?
我认为这可以帮助你。
让我们创建这个辅助对象。
Template.example.helpers({
'editValue' : function(){
return Session.get("TargetValue" + this._id);
}
})
这两件事。
Template.example.events({
'dbclick #spanIdOnDom' : function(e,t){
return Session.set("TargetValue" + t.data._id,true)//hide the span and we set the input
},
'click #buttonToSaveNewValue': function(e, t) {
//here you can take the emailId and the name based on this._id like this Collection.find({_id:this._id}).fetch(); and do the updates you want to do
var newValueFromInput = document.getElementById('newValueFromInput').value;
var idCurrentDocument = this._id;
var Bebida = Collection.findOne(t.data._id);
Collection.update({_id: idCurrentDocument}, {$set:{fieldToUpdate: newValueFromInput}});
return Session.set("TargetValue" + t.data._id,false); //we hide the input and we put the span again
}
})
HTML
<template name="example">
{{#each collectionFind}}
{{#if editValue}}
<input type="text" id="newValueFromInput" value="{{currentValue}} " />
<button class="btn btn-sm btn-primary" id="buttonToSaveNewValue" type="submit">Save new Value</button>
{{else}}
<td>
<p>
<span class="content col-md-10" id="spanIdOnDom" ><h4>Descripcion Bebida:</h4><br>{{currentValue}} </span>
</p>
</td>
{{/if}}
{{/each}}
</template>
当然,您需要设置Allow/deny
权限和publish/subscribe
方法,以使其工作效率更高。
它是如何工作的
在简历中,您有一个具有当前值的<span>
标记,当您在<span>
标记上dobleClick
时,我们将Session设置为true,<span>
标记消失,出现一个带有新按钮的新<input>
,然后我们从<input>
获取值,她将($set)
更新到集合中,并完成此操作。
注意:这是Raj Anand的Meteor中Simple Crud应用程序的迷你回购,但博客上的代码是关于咖啡的,我不使用咖啡脚本。
相关文章:
- 在MVVM视图模型中处理应用程序范围的元素
- Chrome应用程序在全屏中创建新窗口-html元素不是全高的
- 如何在AJAX驱动的应用程序中优化元素绑定
- Chrome应用程序:如何更新在Chrome应用程序主窗口中创建的辅助窗口元素的内容
- Node.js Express应用程序:如果存在cookie,则从服务器端向元素添加CSS类
- 双击以编辑Meteor应用程序中的元素
- 聆听外部应用程序使用 jQuery 对元素所做的样式更改
- 我的应用程序中的可点击元素应始终是锚标记
- 如何在 React 应用程序中不可用的函数中访问 DOM 元素
- 在我的 chrome 网上商店应用程序中禁用检查元素/JavaScript 控制台
- 是否有最适合“拖放”Web应用程序的元素
- Android原生应用程序:无法滚动浏览包含大约200个元素的整个列表(appium java客户端)
- 应用程序后台脚本,访问打开的窗口的元素
- 如何为自定义聚合物元素创建方法并在主应用程序中调用它
- 访问导致我的应用程序崩溃的数组元素
- 选择应用程序各个页面的元素
- jQuery.css():属性中是否存在固有延迟's对元素的应用程序
- 在React+Redux.js应用程序中,在Provider组件之外操作DOM元素的正确方法是什么
- 如何在Aurelia应用程序中使用外部自定义元素(插件)
- 触发iOS键盘在web应用程序的非文本元素