Created
December 30, 2014 02:40
-
-
Save PaulGuo/f3835a5533c4c3b1d8b6 to your computer and use it in GitHub Desktop.
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 pinyin = require('pinyin'); | |
var cities = require('./cityselect-open').data; | |
var pinyinHash = { | |
data: {}, | |
addItem: function(name) { | |
if(this.data.hasOwnProperty(name) || !name) { | |
return; | |
} | |
var pinyinText = pinyin(name, { | |
style: pinyin.STYLE_NORMAL, | |
heteronym: false | |
}).join(''); | |
var pinyinFirstLetter = pinyin(name, { | |
style: pinyin.STYLE_FIRST_LETTER, | |
heteronym: false | |
}).join(''); | |
this.data[name] = { | |
pinyin: pinyinText, | |
acronym: pinyinFirstLetter | |
}; | |
} | |
}; | |
for(var i in cities.data) { | |
if(cities.data.hasOwnProperty(i)) { | |
pinyinHash.addItem(cities.data[i].name); | |
if(!cities.data[i].cities) { | |
continue; | |
} | |
for(var j in cities.data[i].cities) { | |
if(cities.data[i].cities.hasOwnProperty(j)) { | |
pinyinHash.addItem(cities.data[i].cities[j].name); | |
} | |
} | |
} | |
} | |
console.log(pinyinHash.data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment