我一直在试图使用标签云模块从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]
});
});
谢谢!有用! –