M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

No concrete answer so far on this topic

I have seen numerous posts on Appery forum where the user just wants to know what is the "index" of the list item on which someone has clicked. But not a single answer that explains something that is seemingly simple.

I have a list component with the following items
Item 1
Item 2
Item 3

When I click on first item it should show a 0 (the indexes are zero based i guess).

And 2nd thing - when i dynamically add an item to the list component, the list item by default adds the button too. How to prevent the button from being added?

And 3rd thing is
I have added a new list item using list.append method. How can I get a reference to the list item I just added?

I hope that I have explained this in a very simple manner. I hope I can get a clear answer too and not something that will ask me to go and read a tutorial where I cannot find what I want, or a example that simply doesn't answer the question

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

No concrete answer so far on this topic

All that I was looking for was this

code
// lst_projectsList is the list component class

$(".lst_projectsList li a").on('click',function(){
var clicked_item_index = $(".lst_projectsList li a").index(this);
console.log("ID: " + projid_name[clicked_item_index].value + " Name: " + projid_name[clicked_item_index].view);
});
/code

And this is how I have added items to the list
code
var list = Appery("lstprojectsList");
list.empty();

for (var key in projid_name) { // Loop my projects array, add to list
list&#46;append('<li data-name="proj' + projid_name[key]&#46;value + '"><a href="" name="a' + projid_name[key]&#46;value + '">' + projid_name[key]&#46;view + '</a></li>');
}

list&#46;listview('refresh');
/code

Now when I click on the list item I can get the index of the item that was clicked, for example 0 for the 1st item, 1 for then 2nd item....

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

No concrete answer so far on this topic

Hello,

Sorry for radio silence here. Working on it.
We will update as soon as possible.

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

No concrete answer so far on this topic

hi Alena,

I managed to solve it. The solution is given in my post above.

Thanks,
M&M

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

No concrete answer so far on this topic

Hello M&M,

Thank you for the update!

Return to “Issues”