私はhttps://github.com/d-koppenhagen/angular-tag-cloud-moduleからタグクラウドモジュールを使用しようとしていると私のデータオブジェクトは、このようなものです:キーと値を使ってObjectをArrayに変換する方法は?
{ "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]
});
});
ありがとう!できます! –