Corrado's Blog 2.0

Online thoughts of a technology funatic

Clear all elements of a WinJS Binding List

Sometime you need to updatethe contents of a WinJS binding list with new data, this implies removing current elemens and insert new ones.

I was a little surprised not to have a clear method available, but a quick look at documentation provided a powerful alternative, the splice method.

_items.splice(0, _items.length);

using this simple line all elements will be removed.

The method has a 3rd optional parameter representing the items to insert after elements have been removed, but in my experience it looks like that databinding doesn’t seem to recognize them.