Issue Adding list item in code

This forum contains topics that were moved from Get Satisfaction
Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Issue Adding list item in code

Post 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?

Serhii Kulibaba
Posts: 147
Joined: Tue Aug 27, 2013 1:47 pm

Issue Adding list item in code

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

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Issue Adding list item in code

Post by Aeneas McBurney »

When I try above code I get undefined returned in alert

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

Issue Adding list item in code

Post 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.

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Issue Adding list item in code

Post 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?

Image

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

Issue Adding list item in code

Post by Yurii Orishchuk »

Hi Aeneas,

Here is what i see on your screen shot:

  1. incorrect selector for closest element.

  2. 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.

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Issue Adding list item in code

Post 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.

Image

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

Issue Adding list item in code

Post by Yurii Orishchuk »

Hi Aeneas,

Now you use incorrect component for listen event.

See details on screen shot: http://prntscr.com/6yyuoq/direct

Regards.

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Issue Adding list item in code

Post 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

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

Issue Adding list item in code

Post by Evgene Karachevtsev »

Hello Aeneas,

We are sorry for delay, we are working on it and will get back to you with the update.

Post Reply