gpt4 book ai didi

meteor - Meteor 应用程序中的元素保存错误

转载 作者:行者123 更新时间:2023-12-04 15:47:03 35 4
gpt4 key购买 nike

我已经在 Meteor 中制作了一个 watch-as-I-type 实时聊天服务,但是我在 Meteor 中的内置元素保存功能方面遇到了麻烦。基本上,当输入的文本具有焦点时,我需要不更新当前的聊天消息 div。该文档具有以下说明:

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.



按照这些说明,我为我的输入字段设置了一个唯一的 ID,以确保它在我输入时不会被重新呈现。但现在我面临以下两个问题:

其他人的聊天消息会在他们输入时更新,但在我输入自己的消息时,此更新会暂停。一旦我停止输入(即使我的输入字段有焦点),他们的消息又开始更新。

创建新消息并插入其 div 时,即使其输入字段具有焦点,我的消息也会更新/重新呈现。这会导致它突然失去焦点。

您可以在 http://babble.im 在同一聊天室中使用两台不同的计算机/用户对此进行测试。 .

这是 Meteor 代码中的错误还是我自己的错误?我怎样才能知道?

编辑:

啊,我想我找到了第一个问题的原因:

Meteor normally batches up any needed updates and executes them only when your code isn't running. That way, you can be sure that the DOM won't change out from underneath you. Sometimes you want the opposite behavior. For example, if you've just inserted a record in the database, you might want to force the DOM to update so you can find the new elements using a library like jQuery. In that case, call Meteor.flush to bring the DOM up to date immediately.



我猜我的代码在用户输入时正在运行,所以 DOM 没有被更新。我会尝试使用 Meteor.flush要解决这个问题。现在第二个问题怎么办?

最佳答案

第一个问题的原因是 Meteor 过去常常在任何方法运行时卡住对本地数据库缓存的所有更改。 Meteor 0.5.1 对此进行了改进,仅卡住对您在本地修改的文档的更改。我怀疑 Meteor 0.5.1 解决了这个问题。见 http://meteor.com/blog/2012/11/19/latency-compensation-improvements-coming-soon-in-meteor-051想要查询更多的信息。

第二个问题可能由 preserve-inputs 解决。包在 Meteor 0.4.2 中添加,但如果没有更多细节,很难确定。

我很想知道您的问题在当前版本的 Meteor 中是否仍然存在!

关于meteor - Meteor 应用程序中的元素保存错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10202599/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com