Page 1 of 1

delete from list with dividers

Posted: Tue Jan 13, 2015 10:10 pm
by Jakub

I have a list populated from a local storage array.
I have a code that deletes an item from the list when clicked. It worked fine until I added dividers. The reason is that the list index gets reset after each divider. Is there a unique list index or some other way to uniquely identify the list item clicked?

This is the code that used to work, now it deletes randomly
cart is a local object that holds cart_item array

var a = [$(this).index()];

Code: Select all

 var cart = Apperyio.storage.cart.get() || []; 

 cart.splice(a,1); 

  Apperyio.storage.cart.set(cart); 

.


delete from list with dividers

Posted: Wed Jan 14, 2015 5:48 am
by Yurii Orishchuk

Hi Jakub,

Please use following js code on "list item" component click event handler to get correct list-item index:

pre

var li = jQuery(this).closest("li");

var index = li.index('li:not([data-role="list-divider"])');

alert("index = " + index);

/pre

Regards.


delete from list with dividers

Posted: Wed Jan 14, 2015 3:57 pm
by Jakub

Thanks!
It worked perfect!