简体   繁体   English

离子框架相当于Knockout?

[英]Ionic Framework equivalent for Knockout?

I am fond of Durandal and KO frameworks, I just find them to be a more elegant, simpler solution. 我喜欢Durandal和KO框架,我发现它们是一个更优雅,更简单的解决方案。

However Angular with Google behind it had enjoyed better marketing success and hence the more choice of customizations. 然而,与谷歌背后的Angular享有更好的营销成功,因此更多的自定义选择。

Now is there something of equivalent nature on the KO end to Ionic? 现在在离子的KO端有一些等价的东西吗? Or is the war already won and I just need to move on. 或者战争已经赢了,我只需要继续前进。

TL;DR Don't know of any alternative for KO/Durandal but going your own way may be a better choice. TL; DR不知道KO / Durandal的任何替代方案,但走自己的路可能是更好的选择。

What I understand from Ionic it is a wrapper around the core Cordova hybrid framework. 我从Ionic了解到它是核心Cordova混合框架的包装。 As you mentioned it is built with the idea to use AngularJS everywhere. 正如您所提到的,它的构思是在任何地方使用AngularJS。 Besides being a wrapper it also provides additional plugins. 除了作为包装器,它还提供额外的插件。

So essentially if you will it is just a simplification for NG developers. 因此,如果您愿意,它只是NG开发人员的简化。 I don't want to say it is not doing a good job, but actually you can do all of that by your own with Knockout & Durandal as well. 我不想说它做得不好,但实际上你也可以通过自己的Knockout和Durandal完成所有这些工作。 So far I've built a few demo apps with Cordova + Durandal and have to say it's getting better and better, especially the node cli tools provided from Cordova accelerate development a lot. 到目前为止,我已经使用Cordova + Durandal构建了一些演示应用程序,不得不说它越来越好,特别是Cordova提供的节点cli工具可以加速开发。 The big advantage in my view with going this way is that you have complete freedom of what Frameworks and Libraries you choose. 通过这种方式,我认为最大的优势在于您可以完全自由选择框架和库。

  • Choose whatever MVWhatever JS framework you like 选择你喜欢的任何MVWhatever JS框架
  • Choose your GUI Framework (take a look at Ratchet pretty slick :) 选择你的GUI框架(看看Ratchet非常漂亮:)
  • Pick the plugins you need or write them yourself 选择您需要的插件或自己编写
  • Decide which CSS derivate you like best or stick to the basic if you dont care 如果你不在乎,决定你最喜欢哪个CSS派生或坚持基本
  • Enjoy modularization and lazy loading with RequireJS :) 使用RequireJS享受模块化和延迟加载:)

I believe you could just reuse Ionic CSS (like you do with Bootstrap) to get mobile-friendly styling, and then wire up some KO bindings to make it respond to user's actions. 我相信你可以重用Ionic CSS (就像你使用Bootstrap一样)来获得适合移动设备的样式,然后连接一些KO绑定以使其响应用户的操作。

A simple example: imagine you want to make a tabbed interface (i took markup from the docs ) 一个简单的例子:想象你想制作一个标签界面(我从文档中获取标记)

<div class="tabs-striped tabs-top tabs-background-positive tabs-color-light">
    <div class="tabs">
      <a class="tab-item active" href="#">
        <i class="icon ion-home"></i>
        Test
      </a>
      <a class="tab-item" href="#">
        <i class="icon ion-star"></i>
        Favorites
      </a>
      <a class="tab-item" href="#">
        <i class="icon ion-gear-a"></i>
        Settings
      </a>
    </div>
  </div>

With ionic you would have to leverage ion-tabs , but with durandal/KO you have compose and views: 使用离子,你必须利用离子标签 ,但使用durandal / KO,你可以compose和观看:

  <div class="tabs-striped tabs-top tabs-background-positive tabs-color-light" data-bind="delegatedHandler: 'click'">
    <div class="tabs" data-bind="foreach: tabs">
      <a class="tab-item" href="#" data-bind="delegatedClick: $parent.setView.bind($parent), css: {active: isActive}">
        <i class="icon" data-bind="css: icon"></i>
        <span data-bind="text: title"></span>
      </a>
    </div>
  </div>
  <div data-bind="compose: {view: activeView, cacheViews: true}"></div>

And then add a topping in your vm: 然后在你的虚拟机中添加一个顶部:

return {
    tabs: [
        {title:'Test', view: 'test.html', icon: 'ion-home', isActive: ko.observable(false)},
        {title:'Favourites', view: 'favs.html', icon: 'ion-star', isActive: ko.observable(false)},
        ...
    ],
    ,activeView: ko.observable(),
    ,setView: function(view) {
        this.activeView(view.view || view);
        this.tabs.forEach(function(v){
            v.isActive(v.view === viewName);
        });
    }
}

It's just to give you idea of possible approach. 这只是为了让您了解可能的方法。 After all, angular and KO are very similar... And most of ionic's JS components are already implemented in durandal (eg navigation closely resembles routing and composition). 毕竟,角度和KO非常相似......大多数离子的JS组件已经在durandal中实现(例如导航非常类似于路由和组合)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM