Sencha Touch 可以很好地适应像 KnockoutJS 这样的 MVVM 模式吗?

发布于 2024-11-26 14:47:04 字数 425 浏览 0 评论 0原文

我目前正在 KnockoutJS 之上构建一个网络应用程序 - 真的,使用编程的幸福!

我已经到了需要添加移动开发框架的阶段,并且一直在考虑我的选择。

我目前倾向于使用 Sencha Touch,因为它的成熟度和我需要的独特插件。

我唯一担心的是 Sencha Touch 的 OO + 声明式 javascript 编码是否适合 MVVM 框架(例如 Knockout)?

我的意思是 Knockout 利用了视图(HTML 页面)将通过数据绑定调用模型的概念。 ExtJS (Sencha Touch) 不会丰富视图...相反,它期望所有 HTML 内容都以声明方式编写。

我在这里处理的是油和水吗?你的想法是什么。

注意:我很想知道这两种不同的架构是否能够很好地结合在一起。不太有兴趣了解 Sencha Touch 与其他框架的比较。

I am currently building a web-app on top of KnockoutJS - true, programming bliss to use!

I have reached a stage were I need to add a mobile development framework and have been contemplating my choices.

I am currently inclined to go with Sencha Touch because of its maturity and unique plugins which I need.

My only worry is will Sencha Touch's, OO + declarative javascript coding, be a good fit with a MVVM framework such as Knockout?

I mean Knockout leverages off the concept that a View (HTML page) will invoke the model by data-binding. ExtJS (Sencha Touch) does not enrich a View... instead it expects that all the HTML content gets written declaratively.

Am I dealing with oil and water here? What's your thoughts.

Note: I am interested to know if these two different architectures will go well together. Less interested to hear about how Sencha Touch compares to other frameworks out there.

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

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

发布评论

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

评论(4

江心雾 2024-12-03 14:47:04

GluJS 为 ExtJS 3.x 和 4.x 提供 MVVM。 Sencha Touch 绑定正在筹备中。这些人还提供了一种简洁的规范(SVVM)方法。这些东西确实应该成为 Sencha 核心代码库的一部分,并且 ExtJS 4.x 类模型将非常适合,因为 4.x 可以为 GluJS 使用的双向绑定提供钩子。

DeftJS:另一个得到很好支持的好选项是DeftJS;一个开源库,它将带有 ViewControllers 的 MVC(因此不是很完整的 MVVM)添加到 Sencha ExtJS 和 Touch 中。它还添加了控制反转 (IoC) 和 Promises/Deferreds,以实现更清晰的异步编码。

更新...

Sencha ExtJS 5.x 现在支持带有视图模型的完整 MVVM,我们预计下一个主要版本...Sencha Touch 3.x...可能会做同样的事情。 ExtJS 5.x 也进行了更新,包含与 Sencha Touch 相同的核心类和类模型,因此这使得 Touch 3.x 更有可能匹配与 ExtJS 5.x 相同的视图模型。

KnockoutJS 做得很好,但它只是您需要的一部分。不利的一面是,你最终不得不去寻找所有丢失的部分,然后玩“如果可以的话,版本我”,祈祷所有的部分明年仍然得到“某人”的支持。相比之下,Sencha API 提供了在一个版本周期内构建和维护整个应用程序所需的大部分功能。查看这篇博文。

GluJS provides MVVM for both ExtJS 3.x and 4.x . Sencha Touch binding is in the pipeline. These guys also provide a neat specification (SVVM) approach. This stuff should really be part of the Sencha core code base and the ExtJS 4.x class model would be a perfect fit as 4.x can provide hooks for the two way binding that GluJS uses.

DeftJS: Another nice option that has been well supported is DeftJS; an open source lib that adds MVC with ViewControllers (so not quite full MVVM) to both Sencha ExtJS and Touch. It also adds inversion of control (IoC) and Promises/Deferreds for cleaner asynchronous coding.

Update ...

Sencha ExtJS 5.x now supports full MVVM with View Models and we expect that the next major release ... Sencha Touch 3.x ... will likely do the same. ExtJS 5.x was also updated to include the same core classes and class model as Sencha Touch so this make it even more likely that Touch 3.x will match the same View Model as ExtJS 5.x .

KnockoutJS does what it does very well but it's just one part of what you need. The down side is that you end up having to go and hunt for all the missing pieces and then play "version me if you can" crossing your fingers that all the bits are still supported next year by "someone". In contrast, Sencha APIs provide most of what you need to build and maintain the whole app under one version cycle. Check out the heading "The Modern Web Stack" under this blog post.

兲鉂ぱ嘚淚 2024-12-03 14:47:04

这是石油,而且是……另一种石油。 Sencha Touch 拥有自己的 MVC 式架构,具有数据绑定和模板,以及大量其他内容,例如移动小部件、事件处理、主题、图表和图表。可视化库等。我预测您在尝试混合这两者时会遇到严重困难。但如果你设法做到这一点,我们很乐意听到它(我是一个 sencha 人)

更新:正如托尼下面提到的 - 自从我回答这个问题以来,Sencha 的 glu.js 已经问世了 - http://www.conarrative.com/glujs.html。如果您想要 MVVM 风格而不是 MVC,那么这几乎正是您所寻找的(我们喜欢他们的方法)

This is oil and ... a different sort of oil. Sencha Touch has its own MVC'ish architecture with data binding and templating, and also a huge amount of other stuff like mobile widgetry, event handling, theming, charting & visualization libraries etc. I would forecast that you'll have severe difficulties trying to mix the two. But if you manage to do it, we'd love to hear about it (I'm a sencha person)

Update: As Tony mentions below - glu.js for Sencha has come out since I answered this question - http://www.conarrative.com/glujs.html. It's pretty much exactly what you're looking for if you want a MVVM style vs. a MVC (and we like their approach)

单身情人 2024-12-03 14:47:04

这绝对是可能的,我在上一个项目中确实使用了这两种方法。然而,您需要放弃最有趣的部分:dom 元素绑定和大多数商店的功能。相反,您需要监听视图模型更改并相应地更新 ExtJS 视图。并非所有 ExtJS 组件都是可绑定视图的,以滑块为例。因为我是一个 Flex 人(你可以在 Flex 中绑定任何东西,说实话,在使用只需输入 {} 进行绑定后,其他一切都很糟糕(是的,甚至是 sencha)),我感觉有些不对劲,并为我的模型使用了淘汰赛。我们在这里讨论的是 var a 更新 var b 更新 var c 的变化,所以淘汰赛在那里是完美的。很多事情都必须手动完成,比如模型视图绑定,最后我不能说我对结果感到自豪,因为它不是最有组织的代码(实际上看起来很丑),我不会推荐它除非你的模型之间有很多依赖关系。

It's definitely possible and i did use both for my last project. However you need to let go knockouts most interesting part: dom element bindings and most of the stores' abilities. Instead you need to listen view model changes and update ExtJS views accordingly. Not all the ExtJS components are view bindable, lets take sliders for example. Since I am a Flex person (you can bind anything in flex and to be honest everything else sucks (yep even sencha) after getting used binding with just typing {}) I felt something wrong and used knockout for my model. We're talking about var a updating var b updating var c on change here so knockout was perfect there. A lot had to be done by hand, like model view bindings and in the end i can't say i'm proud of the result since it is not the most organized code (looks pretty ugly actually) and I wouldn't recommend it unless you have a lot of dependencies between your models.

情何以堪。 2024-12-03 14:47:04

我写了一篇博客文章,概述了 Sencha Touch 中 MVVM 模式的一种方法 使用 Sencha Touch 内置的 MVC 技术,无需依赖其他框架。

本质上,这个想法围绕 Sencha Touch 非常“基于存储”的事实:当记录更改时,事件会在记录的存储上触发,而不是在记录本身上触发。因此,如果我们将模型视图的 xtypes 与存储相关联,我们可以简单地迭代这些视图,并在记录更改时根据需要更新它们。

总的来说,这个解决方案只有几十行。如果您不想学习其他框架(例如 GluJS),那么它是一个很好的轻量级替代方案。

I wrote a blog post that outlines one approach to a MVVM pattern in Sencha Touch that uses Sencha Touch's built-in MVC technology without replying on another framework.

Essentially the idea revolves around the fact that Sencha Touch is very "store-based": when a record is changed, the event fires on the record's store(s), not on the record itself. So if we associate the xtypes of model-views with a store, we can simply iterate over those views and update them as needed when a record changes.

In total this solution is just a couple dozen lines. It's a good lightweight alternative if you're not up to learning another framework like GluJS.

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