Ionic Dynamic List Divider

后端 未结 3 1982
悲哀的现实
悲哀的现实 2021-02-14 23:04

I have been stumped on this problem for a while now, so I am hoping you can get me in the right direction.

My angular factory returns an object which looks like this

3条回答
  •  你的背包
    2021-02-14 23:45

    I'm not sure if this is the best way of doing it, but I built a CodePen that does this:

    • Take an original list (this would be your real data)
    • Modify the list by creating additional items for unique starting letters
    • In the view, we see if our data is a letter, and if so, treat it as a list divider

    This is kind of like how one of their pens work (http://codepen.io/ionic/pen/uJkCz). It feels slightly wrong to me, but it seems to work well. Here is the controller portion:

    .controller('RootCtrl', function($scope) {
    
      //orig data
      var list = [];
      list.push({name:"Gary"});
      list.push({name:"Gosh"});
      list.push({name:"Ray"});
      list.push({name:"Sam"});
      list.push({name:"Sandy"});
    
      $scope.list = [];
      var lastChar = '';
      for(var i=0,len=list.length; i

    And then the view checks to see if the data is a person vs a letter. Again, this feels a bit lame, but...

    
      
        {{person.name}}
      
    
    

    You can run this here: http://codepen.io/cfjedimaster/pen/HqrBf

提交回复
热议问题