我一直在試圖使用標籤雲模塊從https://github.com/d-koppenhagen/angular-tag-cloud-module,我的數據對象是這樣的:如何將對象轉換爲帶有鍵和值的數組?
{ "Speech": 4, "E-commerce": 1, "Meeting": 1, "Garena": 1 , "Silicon valley": 1}
根據模塊的指導,數據陣列應該插入像下面這樣:
[ {text: "Speech", weight: 4}, {text: "E-commerce", weight: 1}, {text: "Meeting", weight: 1},{text: "Garena", weight: 1}, {text: "Sillicon valley", weight: 1}]
我的代碼位於下方,最近剛剛用Typescript編碼,希望有人能給我一個提示!
var post_tags: Array<string> = post['tags'];
post_tags.forEach(element => {
this.counts[element] = (this.counts[element] || 0)+1;
this.tags.push({
text: Object.keys(this.counts),
weight: this.counts[element]
});
});
謝謝!有用! –