Sorting not working with Knockout and Isotope

走远了吗. 提交于 2019-12-12 00:18:06

问题


Update: forgot the one question per question rule. Cut second question out of this one.

Trying to make a list of users sortable by different criteria with animation. Was already using Knockout so this demo seemed like a good direction to take. I switched to an Isotope 2.0 fork of the integration code here.

Sometimes the sorting doesn't update properly, as shown in this version - http://codepen.io/matelich/pen/PPoqdz - Medal and Component should have #0 and #1 switched from each other, but the ui doesn't update.

        switch (content) {
           case 'alphabetTab':  
              ViewModel.users.sort(function (u1, u2) { 
                 return u1.UserName.localeCompare(u2.UserName); 
              }); 
              break;
           case 'medalTab':
              ViewModel.users.sort(function(u1, u2) {
                 return u1.MedalScore < u2.MedalScore ? 1 : (u1.MedalScore > u2.MedalScore ? -1 : 0);
              });
              break;
          case 'componentTab':
             ViewModel.users.sort(function(u1, u2) {
                return u1.LearnedComponents < u2.LearnedComponents ? 1 : (u1.LearnedComponents > u2.LearnedComponents ? -1 : 0);
             });
        }
        for (i = 0; i < ViewModel.users().length; i++) {
           console.log(ViewModel.users()[i].UserName);
        }
        ViewModel.users.valueHasMutated();

来源:https://stackoverflow.com/questions/32303258/sorting-not-working-with-knockout-and-isotope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!