Jakub
Posts: 0
Joined: Fri Dec 05, 2014 10:53 pm

delete from list with dividers

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); 

.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

delete from list with dividers

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.

Jakub
Posts: 0
Joined: Fri Dec 05, 2014 10:53 pm

delete from list with dividers

Thanks!
It worked perfect!

Return to “Issues”