Created
May 17, 2017 19:13
-
-
Save yozef/7e3174e3087610686b6a11d8793dc7fc to your computer and use it in GitHub Desktop.
TableView Indexes require an array of [{index: i, title: first_char_name}] this loop creates the rows + the index array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var indexArray = []; | |
var currentChar = ''; | |
var lastChar = ''; | |
// the Array e.places is already sorted alphabetically from ACS with order:'name' in query | |
for (var i = 0; i < e.places.length; i++) { | |
var farm = e.places[i]; | |
// create an index of first chars of the farm name | |
currentChar = farm.name.charAt(0); | |
if (i == 0) indexArray.push({title: currentChar, index: i}); | |
else { | |
if (lastChar != currentChar) indexArray.push({title: currentChar, index: i}); | |
} | |
arrayForTableView.push({ title: farm.name, selectedBackgroundColor:'#50C45A' } ); | |
lastChar = currentChar; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment