Meteor - 有没有办法让 div contenteditable 双向数据绑定工作? [英] Meteor - Is there a way to get div contenteditable two way data binding to work?
本文介绍了Meteor - 有没有办法让 div contenteditable 双向数据绑定工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无法将双向数据绑定附加到
标记.这里是演示
html:
<div contenteditable style="height:40px;min-width:40px">{{content}}</div>
js:
if (Meteor.isClient) {Session.setDefault('content', '尝试编辑我')Template.body.helpers({内容:函数(){返回 Session.get('内容')}})模板.body.events({'keydown div':函数(e){setTimeout(function(){ Session.set('content', $(e.target).text()) })}})}
在 github 上还有一个未解决的问题.
解决方案
或者直接使用 https://github.com/gwendall/meteor-bindings.它利用反应变量将任何 DOM 元素绑定到输入.
免责声明:我构建了它.
Unable to attach two way data binding to a <div contenteditable>
tag. Here is the demo
html:
<body>
<div contenteditable style="height:40px;min-width:40px">{{content}}</div>
</body>
js:
if (Meteor.isClient) {
Session.setDefault('content', 'Try to edit me')
Template.body.helpers({
content: function () {
return Session.get('content')
}
})
Template.body.events({
'keydown div': function (e) {
setTimeout(function(){ Session.set('content', $(e.target).text()) })
}
})
}
There is also an open issue for this at github.
解决方案
Or just use https://github.com/gwendall/meteor-bindings. It makes use of reactive variables to bind any DOM element to inputs.
Disclaimer: I built it.
这篇关于Meteor - 有没有办法让 div contenteditable 双向数据绑定工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文