javascript - 从 json feed Angular 4 中的表中检索数据

标签 javascript json angular

我有一个返回此结果的函数:

    {id: 20, dateCreation: 1517324655450, auteurCreation: "bel", dateModification: 1530544886148, auteurModification: "user", …}
    auteurCreation:"bel"
    auteurModification:"user"
coupesTechniquesDescription:Array(1)
0:{id: 15, hauteurReference: 2, commentaireReference: "test"}
length:1
__proto__
:Array(0)
dateCreation:1517324655450
id:20

我想将:coupesTechniquesDescription保存在变量中, 目标是获取 coupesTechniquesDescription 列表并使用第一个索引

最佳答案

给你。从 res 中获取对象:

// define the variable above your constructor
private coupesTechniquesDescription;

constructor(...){
    this.technicalservice.find(this.id).subscribe((res) => { 
        this.coupesTechniquesDescription = res.coupesTechniquesDescription[0];

        console.log(this.coupesTechniquesDescription);
    }, 
    (err) => { console.log("Erreur"); });

}

关于javascript - 从 json feed Angular 4 中的表中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51187216/

相关文章:

javascript - 在 div 的边界内动画图片

C# GET请求和解析JSON

angular - 您的请求失败。使用其他付款方式,或联系我们。了解 Google Pay 中的详情 [OR-CCSEH-21]

javascript - jQuery 焦点事件似乎在 qUnit 测试中不起作用

javascript - 嵌套 jQueryeach() + json

javascript - 如何制作类似 GreaseMonkey 的脚本以在下三分之一处显示不同的页面?

c# - 将 Json 字符串反序列化为 Enum C#

c# - 将字典 <string, object> 传递给 MVC Controller

angular - 将授权 header 添加到 Springfox

javascript - 如何在 Angular 2中的模板 View 内进行嵌套循环