不引人注目的淘汰赛,没有 dom 污染

发布于 2025-01-07 09:05:07 字数 290 浏览 0 评论 0原文

是否有任何“不显眼的淘汰”插件不会将数据绑定属性重新引入到 dom 的元素中? 我尝试过一些类似的: http://userinexperience.com/?p=633 和 Jquery 插件。

所有这些的问题在于它们不断将数据绑定引入到 dom 中。有没有其他插件可以做更多的事情,比如将数据绑定放入扩展中,例如 http://docs.jquery.com/数据

Are there any "unobtrusive knockout" plugins which do not reintroduce the data-bind attribute to the elements to the dom?
I've tried a few like: http://userinexperience.com/?p=633
and the Jquery plugin.

The problem with all of them is that they keep introducing data-bind back into the dom. Is there anything other plugin which can do something more along the lines of putting data-bind in a expando like http://docs.jquery.com/Data

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

筱果果 2025-01-14 09:05:07

淘汰赛。 Unobtrusive 插件是我摆脱 data-bind 属性的最初尝试,当我创建它时,将绑定模型元素添加回 DOM 是我能想到的唯一合理的方法这。

正如 Ryan 上面指出的,Knockout 2.0 允许创建自定义绑定提供程序,用您的首选策略替换 data-bind 属性。因此,我目前正在更新我的插件以提供这些提供程序之一,这将消除运行时对 DOM 的任何写入。您可以在此处查看我在 ko-v2 分支上的进度。如果您有任何意见或建议,请告诉我。请注意,我刚刚开始,所以还没有任何效果,但我应该在第二天左右再进行一两次提交来分享。


2-28-12 更新

我在上面的分支添加了一些额外的测试和功能。当前的功能是基本的,但到目前为止可以满足您规避数据绑定的要求。

让我知道你的想法。这可能最终会被剥离到一个新项目中(Knockout.Unobtrusive 关闭)

The Knockout. Unobtrusive plugin was my initial attempt to move away from data-bind attributes, and back when I created it, adding binding model elements back to the DOM was about the only reasonable way I could come up with do do this.

As Ryan points out above, Knockout 2.0 allows the creation of custom bindings providers that replace data-bind attributes with your preferred strategy. As such, I'm currently in the process of updating my plugin to provide one of these providers, which would eliminate any writing to the DOM at runtime. You can checkout my progress on the ko-v2 branch here. Let me know if you have any comments or suggestions. And be warned, I'm just getting started, so nothing is working yet, but I should have another commit or two to share in the next day or so.


2-28-12 Update

I've added some additional tests and functionality at the branch above. The current functionality is basic, but so far meets your requirement of circumventing data-bind.

Let me know what you think. This may end up being spun off into a new project (with Knockout.Unobtrusive shutting down)

垂暮老矣 2025-01-14 09:05:07

以下文章介绍了如何创建您自己的自定义绑定提供程序: http://www.knockmeout.net/2011/09/ko-13-preview-part-2-custom-binding.html

创建一个自定义绑定提供程序非常容易,该提供程序可以从 jQuery $.data 或作为 Expando 属性保存/加载其数据(可以使用 ko.utils.domData.get/set)。

绑定提供者只需要实现nodeHasBindingsgetBindings函数。

如果您需要进一步帮助实施类似的事情,请告诉我。

Here is an article that shows how to create your own custom binding provider: http://www.knockmeout.net/2011/09/ko-13-preview-part-2-custom-binding.html.

It would be easy enough to create a custom binding provider that saves/loads its data from either jQuery $.data or as an expando property (can use ko.utils.domData.get/set).

The binding provider just needs to implement nodeHasBindings and getBindings functions.

If you need further help implementing something like this, then let me know.

甜宝宝 2025-01-14 09:05:07

很抱歉重新打开一个旧问题,但我一直在寻找类似的问题,但找不到足够灵活的东西来满足我们的需求。我只花了大约 30 分钟编写自己的内容,这就是我的想法。

Sorry to reopen an old question but I was looking for something like this and couldn't find something flexible enough for our needs. Only took around 30 minutes to write my own, here's what I came up with.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文