不显眼的淘汰赛 [英] Unobtrusive Knockout
问题描述
我最近开始了解 Knockout,我认为这是一个很棒的框架.不过我有一个顾虑.
I've recently got up to speed with Knockout and I think it's a fantastic framework. However I have one concern.
我发现在非平凡的绑定情况下,我的视图(标记)中有一些 javascript 代码片段.事实上,Knockout 文档中的很多代码示例也证明了这一点.
I'm finding that in non-trivial binding cases, I have snippets of javascript code creeping into my view (markup). In fact quite a few code samples in the Knockout documentation demonstrate this too.
这是否会使 Knockout 本身显得突兀?
我是否应该接受它的现状而不是在实践中担心?
Should I just accept it for what it is and not be worried in practice?
或者我应该采用什么模式/技术来让 Knockout 不引人注目?
推荐答案
很好的问题.我一直在编写复杂的 KnockoutJS 视图,直到我切换到 Ryan Niemeyer 的类绑定提供程序.
Great question. I've been writing complex KnockoutJS views for awhile and was never satisfied until I switched to Ryan Niemeyer's class binding provider.
Knockout ClassBindingProvider 允许您在 JavaScript 对象中声明绑定,然后从类似于 css 类的工作方式的 data-class
属性引用它们.效果很好!
The Knockout ClassBindingProvider allows you to declare your bindings in a JavaScript object and then reference them from a data-class
attribute similar to how css classes work. It works great!
这篇关于不显眼的淘汰赛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!