How to architecture a webapp using jquery-mobile and knockoutjs

后端 未结 1 1576
长发绾君心
长发绾君心 2020-12-12 08:47

I would like to build a mobile app, brewed from nothing more but html/css and JavaScript. While I have a decent knowledge of how to build a web app with JavaScript, I though

相关标签:
1条回答
  • 2020-12-12 09:11

    Note: As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live().

    I'm working on the same thing (knockout + jquery mobile). I'm trying to write a blog post about what I've learned but here are some pointers in the meantime. Remember that I'm also trying to learn knockout/jquery mobile.

    View-Model and Page

    Only use one (1) view-model object per jQuery Mobile-page. Otherwise you can get problems with click-events that are triggered multiple times.

    View-Model and click

    Only use ko.observable-fields for view-models click-events.

    ko.applyBinding once

    If possible: only call ko.applyBinding once for every page and use ko.observable’s instead of calling ko.applyBinding multiple times.

    pagehide and ko.cleanNode

    Remember to clean up some view-models on pagehide. ko.cleanNode seems to disturb jQuery Mobiles rendering - causing it to re-render the html. If you use ko.cleanNode on a page you need to remove data-role’s and insert the rendered jQuery Mobile html in the source code.

    $('#field').live('pagehide', function() {
        ko.cleanNode($('#field')[0]);
    });
    

    pagehide and click

    If you are binding to click-events - remember to clean up .ui-btn-active. The easiest way to accomplish this is using this code snippet:

    $('[data-role="page"]').live('pagehide', function() {
        $('.ui-btn-active').removeClass('ui-btn-active');
    });
    
    0 讨论(0)
提交回复
热议问题