Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 17c5879

Browse files
author
Gabriel Schulhof
committed
Listview: Add method updateItems()
In refresh() we still need to retrieve all list items, even when we get a list of items from updateItems(), because the followings require global knowledge: - Which items have been removed since last time, so we can untrack them - Which is the first resp. last item for use with addFirstLastClasses()
1 parent de77290 commit 17c5879

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

js/widgets/listview.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ return $.widget( "mobile.listview", $.extend( {
129129
_beforeListviewRefresh: $.noop,
130130
_afterListviewRefresh: $.noop,
131131

132+
updateItems: function( items ) {
133+
this._refresh( false, items );
134+
},
135+
132136
refresh: function() {
133137
this._refresh();
134138
},
@@ -141,10 +145,11 @@ return $.widget( "mobile.listview", $.extend( {
141145
return true;
142146
},
143147

144-
_refresh: function( create ) {
148+
_refresh: function( create, items ) {
145149
var buttonClass, pos, numli, item, itemClass, itemExtraClass, itemTheme, itemIcon, icon, a,
146150
isDivider, startCount, newStartCount, value, last, splittheme, splitThemeClass, li, ol,
147151
altButtonClass, dividerTheme, start, itemClassDict, dictionaryKey, span, spliticon,
152+
allItems,
148153
currentOptions = this.options,
149154
createEnhanced = create && this.options.enhanced,
150155
list = this.element;
@@ -161,7 +166,10 @@ return $.widget( "mobile.listview", $.extend( {
161166

162167
this._beforeListviewRefresh();
163168

164-
li = this._getChildrenByTagName( list[ 0 ], "li", "LI" );
169+
// We need all items even if a set was passed in - we just won't iterate over them in the
170+
// main refresh loop.
171+
allItems = this._getChildrenByTagName( list[ 0 ], "li", "LI" );
172+
li = items || allItems;
165173

166174
for ( pos = 0, numli = li.length; pos < numli; pos++ ) {
167175
item = li.eq( pos );
@@ -269,7 +277,7 @@ return $.widget( "mobile.listview", $.extend( {
269277

270278
this._afterListviewRefresh();
271279

272-
this._addFirstLastClasses( li, this._getVisibles( li, create ), create );
280+
this._addFirstLastClasses( allItems, this._getVisibles( allItems, create ), create );
273281

274282
// Untrack removed items
275283
if ( this._oldListItems ) {
@@ -279,7 +287,7 @@ return $.widget( "mobile.listview", $.extend( {
279287
} ),
280288
"ui-listview-item ui-listview-item-static ui-listview-item-has-count " +
281289
"ui-listview-item-has-alternate ui-listview-item-divider" );
282-
this._oldListItems = li;
290+
this._oldListItems = allItems;
283291
}
284292
}
285293
}, $.mobile.behaviors.addFirstLastClasses ) );

0 commit comments

Comments
 (0)