我有一个API返回给我一个JSON,其中的音符范围从1到5,我需要在变量中存储一定数量的音符。在变量中保存相同音符的数量 - Angular 2
例子:
var n1 = 5; // Quantity of 10 notes with a value of 1 - [1,1,1,1,1]
var n2 = 3; // Quantity of 3 notes with a value of 2 - [2,2,2]
var n3 = 4; // Quantity of 4 notes with a value of 3 - [3,3,3,3]
我的JSON看起来是这样的:
[
{
"author": "Lorem ipsum",
"note": "5",
"description": "Lorem ipsum dolor sit amet"
}
]
而且我用这个代码是这样的:
numNotas() {
this.http.get(this.url).map(res => res.json())
.subscribe(data => {
console.log(data);
});
}
我试图用类似console.log(data.note)
试图列出只有数字,我可以尝试一些东西来保存相同的音符在respecti ve变量,但console
返回我undefined
。那么,我怎么能得到这些相同的笔记,并以正确的方式将它们保存在变量中呢?
请注明您所使用angular2和rxjs在你的标签。 – WilomGfx
@WilomGfx是的。我可以正常打印数据。我的问题是真的将变量保存在变量中。 –