Knockout and jQuery Mobile: Binding data to select lists

后端 未结 4 1350
Happy的楠姐
Happy的楠姐 2020-12-29 14:17

I\'m using both Knockout (version 2.0) and jQuery Mobile (version 1.0.1) in the same project. The problem is with binding data to select lists. jQuery Mobile presents select

4条回答
  •  自闭症患者
    2020-12-29 14:55

    Just for clarity, the best solution now for KO 3.x would be:

    ko.bindingHandlers.jqmValue = {
        init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
          if (typeof ko.bindingHandlers.value.init !== 'undefined') {
            ko.bindingHandlers.value.init(element, valueAccessor, allBindingsAccessor, viewModel);
          }
        },
        update: function(element, valueAccessor, allBindingsAccessor, viewModel) {
          var instance;
          if (typeof ko.bindingHandlers.value.update !== 'undefined') {
            ko.bindingHandlers.value.update(element, valueAccessor, allBindingsAccessor, viewModel);
          }
          instance = $.data(element, 'mobile-selectmenu');
          if (instance) {
            $(element).selectmenu('refresh', true);
          }
        }
      };
    

    And the matching HTML use:

    
    

提交回复
热议问题