Page 1 of 2
Issue Adding list item in code
Posted: Wed Apr 15, 2015 7:37 pm
by Aeneas McBurney
I have a list that I am adding items to dynamically with the below code.
var expenses=JSON.parse(localStorage.getItem("expenseDetails"));
li.empty();
for (var i = 0; i < expenses.length; i++) {
if(expenses.jobID==jno){
var litext=expenses.type + '-' +expenses.description +' $'+ expenses.value;
newexp="" + litext +"";
li.append(newexp).listview('refresh');
}
}
The id of each item I want to be the expense id so when I click on it I know which one it is. However the id is not being picked up and instead the id being returned is something like mobilelistitem_258_2.
The code on click event on the list item is
var eno=$(this).closest("li").attr('id');
How do I return my id?
Issue Adding list item in code
Posted: Fri Apr 17, 2015 2:33 pm
by Serhii Kulibaba
Hello Aeneas,
Elements "li" doesn't have id attribute, you can get attribule "id" from it's child element "a":
var eno=$(this).closest("li a").attr('id');
Issue Adding list item in code
Posted: Sun Apr 19, 2015 8:44 pm
by Aeneas McBurney
When I try above code I get undefined returned in alert
Issue Adding list item in code
Posted: Tue Apr 21, 2015 1:36 am
by Yurii Orishchuk
Hi Aeneas,
Your code is not readable cause of it was not escaped with <pre.....</pre tag.
Please read following thread to understand how to add list-items dynamically:
https://getsatisfaction.com/apperyio/...
Regards.
Issue Adding list item in code
Posted: Tue Apr 21, 2015 1:51 am
by Aeneas McBurney
Here is a screenshot of the code I'm using to fill the list and to retrieve the value back on click. When I do the 2nd part I get undefined for the alert(eno). How do I get the expense ID from the dynamic list I created?
Issue Adding list item in code
Posted: Wed Apr 22, 2015 10:58 pm
by Yurii Orishchuk
Hi Aeneas,
Here is what i see on your screen shot:
incorrect selector for closest element.
incorrect attribute(you store "name" but trying to get "id").
Details:
http://prntscr.com/6x1lug/direct
Here is possible way to fix it:
details: http://prntscr.com/6x1mjy/direct
Regards.
Issue Adding list item in code
Posted: Wed Apr 22, 2015 11:27 pm
by Aeneas McBurney
I tried what you said but it didn't work. Please see screenshot for what its doing(red) and what I want it to do(green). My expense list is within a job list and grid.
Issue Adding list item in code
Posted: Mon Apr 27, 2015 11:38 pm
by Yurii Orishchuk
Hi Aeneas,
Now you use incorrect component for listen event.
See details on screen shot: http://prntscr.com/6yyuoq/direct
Regards.
Issue Adding list item in code
Posted: Fri May 01, 2015 5:14 pm
by Aeneas McBurney
HI Yurii,
I changed the click event to the listitem but its now not being triggered. I think this is because I have filled the list items from javascript but I need to be able to do this and then return the expense ID.
Thanks,
Aeneas
Issue Adding list item in code
Posted: Tue May 05, 2015 9:56 am
by Evgene Karachevtsev
Hello Aeneas,
We are sorry for delay, we are working on it and will get back to you with the update.