SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    replace works once :(

    Hi,
    may be monday morning
    but I don't understand why on earth this
    snippet works only the first time
    PHP Code:
    $container.on('click','th.sortable i',function(e){
             
    e.preventDefault();
             var 
    $this = $(this);
             var 
    path = $('.pagination li.active').attr('data-url');
             var 
    removeCls $this.attr('class');
             
    $this.removeClass(removeCls);
             var 
    $th $this.closest('th');
             var 
    orderby $th.attr('data-orderby');
             if(
    removeCls==='icon-circle-arrow-down'){
                
    orderby++
                
    $this.addClass('icon-circle-arrow-up');
             }
             else{
                
    $this.addClass('icon-circle-arrow-down');
                
    orderby--;
            }
            
    $th.attr('data-orderby',orderby);
            
    console.log(path);
            var 
    newPath path.replace(/orderby\/[0,9]/,'orderby\/'+orderby);
            
    console.log(newPath);
            
    console.log(orderby);
     }); 
    when I click the first time if I've got
    in path
    /en/admin/users/index/page/1/orderby/0/np/3
    and in orderby 7
    I got
    /en/admin/users/index/page/1/orderby/7/np/3

    the second time
    /en/admin/users/index/page/1/orderby/7/np/3
    /en/admin/users/index/page/1/orderby/7/np/3
    and ibn orderby 6

  2. #2
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var newPath = path.replace(/orderby\/(\d+)/,'orderby\/'+orderby);
    thanks the same

  3. #3
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    btw if you see something wrong with the regex tell me


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •