This is a migrated thread and some comments may be shown as answers.

Listview Click event

1 Answer 336 Views
ListView (Mobile)
This is a migrated thread and some comments may be shown as answers.
Chuck
Top achievements
Rank 1
Chuck asked on 21 Jan 2015, 06:07 PM
I have a mobile listview configured and working correctly to display a list of items that a user can select. They can select multiple items. When the user selects an item I simply add/remove the item from an array. The problem is that if they click the same item too fast then code code does not see the item in the array because the first pass through the click function hasn't finished when the second click happens. 

Is there a way to handle this type of situation

$("#selectList").kendoMobileListView({
        dataSource: ViewModel.get("itemsource"),
        template: $("#tmpl-selection-list").text(),
        pullToRefresh: false,
        click: ViewModel.itemSelected
});

itemSelected: function(e){
            var item = e.dataItem, addIt = true, currentItems = [];              
            currentItems = ViewModel.get("itemsource");
            if(item !== null){
                $.each(currentItems, function(s, _item){
                     if(item.blog_id === _item.blog_id){
                        addIt = false;
                }
             });
                    
             if(addIt){
                 currentItems.push(item);
             } else {
                 currentItems = $.grep(currentItems, function(o) {
                   return o.blog_id !== item.blog_id;
              });
            }
            ViewModel.set("itemsource", currentItems);
        }
 },
        

1 Answer, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 23 Jan 2015, 08:44 AM
Hi Chuck,

this seems unlikely. Unless I am missing something, the code you have posted does not have any asynchronous calls in it, so the error probably is somewhere else. You can verify that by putting console.log at the start/end of the callback. 

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
ListView (Mobile)
Asked by
Chuck
Top achievements
Rank 1
Answers by
Petyo
Telerik team
Share this question
or