Created
October 1, 2012 04:53
-
-
Save FirstVertex/3809531 to your computer and use it in GitHub Desktop.
Updating Knockout-bound jQuery Mobile Listview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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