Skip to content

Instantly share code, notes, and snippets.

@FirstVertex
Created October 1, 2012 04:53
Show Gist options
  • Save FirstVertex/3809531 to your computer and use it in GitHub Desktop.
Save FirstVertex/3809531 to your computer and use it in GitHub Desktop.
Updating Knockout-bound jQuery Mobile Listview
<!-- the refreshListview here instructs Knockout to call a binding handler by that name -->
<!-- ko foreach: members, refreshListview: true
--><li style="padding:.3em">
<span data-bind="text: memberName, css: { memberIsTyping: isTyping }"></span>
</li><!-- /ko -->
// the refreshListview Knockout bindingHandler implemented in SmartJs
Ko.bindingHandlers.refreshListview = {
update: function (element, valueAccessor) {
Ko.utils.unwrapObservable(valueAccessor()); //just to create a dependency
if (!element) return;
Logger.log('Ko.bindingHandlers.refreshListview.update() > element.nodeName',
element.nodeName);
var ul = (element.nodeName === 'UL') ?
Jquery(element) :
Jquery(Ko.virtualElements.firstChild(element)).closest('ul');
if (!ul || !ul.length) return;
setTimeout(function (ul) { ul.listview('refresh'); }, 0, ul);
}
};
// allow this to be used on a comment-style (virtual) binding
Ko.virtualElements.allowedBindings.refreshListview = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment