meteor - 在 Meteor 应用程序中设置 Textarea 值的正确方法是什么?

标签 meteor

目前,如果代码包含类似的东西

<div>{{some_value}}</div>

完美运行。 鉴于

<textarea>{{some_val}}</textarea> 

仅当光标不在文本框中时有效

最佳答案

这是 Meteor 的故意行为。在文档中:

Another thorny problem in hand-written applications is element preservation. Suppose the user is typing text into an element, and then the area of the page that includes that element is redrawn. The user could be in for a bumpy ride, as the focus, the cursor position, the partially entered text, and the accented character input state will be lost when the is recreated.

This is another problem that Meteor solves automatically. Just make sure that each of your focusable elements either has a unique id, or has a name that is unique within the closest parent that has an id. Meteor will preserve these elements even when their enclosing template is rerendered, but will still update their children and copy over any attribute changes.

Meteor 不会更新 <input><textarea>有焦点,因为在许多情况下,如果用户试图输入某些内容,这会对用户造成很大的干扰(想象一下,当突然被覆盖时,您正在字段中键入一个段落)。但是,这确实意味着当用户与另一个用户或其他 react 性更改“冲突”时,他们将不会获得更新。如果你想覆盖这个行为,你可能有一个隐藏的 <div>或一个 js 数据元素,您使用它来为您的应用程序进行适当的更新(可能标记有新值或简单地覆盖它)。这种碰撞处理起来并不简单,可能需要根据情况采取不同的行为。也许 Meteor 的 future 版本会给我们一些工具来简化处理。有关更多背景信息,请参阅 this post .

关于meteor - 在 Meteor 应用程序中设置 Textarea 值的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11960260/

相关文章:

javascript - meteor &出版锁

meteor - 使用 Meteor Iron-router 中止导航

meteor - 发布前更改集合

javascript - 在 React (v0.14.8) 中加载 Meteor (v1.3) 数据的首选方式

android - 如何从 Android 应用程序向 meteor 服务器发出发布请求

javascript - 当 Router.route(uri, {name : templateName })

javascript - 当登陆已经有一个 init 的路线/模板时,meteor-bootstrap-datetimepicker 会出现错误

javascript - 我无法在我的网站上获取任何图片或显示任何 URL 图片

javascript - 在集合中搜索游标的元素

javascript - 在 Meteor 中添加公共(public) JS