【问题标题】:display json data in a html table在 html 表中显示 json 数据
【发布时间】:2020-06-18 22:04:18
【问题描述】:

基本上我所做的就是通过 python server-werkzeug 将一些数据插入到数据库中。 以及从数据库中检索这些数据的另一个功能。浏览器控制台中显示的结果一切正常。 现在如何在 html 表中打印 json 格式的结果。 我的代码非常简单,它不包含任何 ngAapp 或 ngController。

import { Component } from '@angular/core';
import {Http, Response, Headers} from '@angular/http';

@Component({
    selector: 'app-meta',
    templateUrl: './meta.component.html',
    styleUrls: ['./meta.component.css']
})
export class MetaComponent  {
    res: any[];
    json;

    constructor(private http: Http) {}

    public getall(){
    // alert('error');
        const data = {
            "jsonrpc" : "2.0",
            "method" : "getall",
            "id" : "1",
            "params": {'argument' : 'something' }
        };
        this.http.post('http://localhost:80/jsonrpc', data).subscribe( res => console.log(this.json =   
res.text()));
        // ...

HTML:

<button (click)="getall()">view</button>
<pre>{{json}}</pre>

点击按钮后我在 html 页面中得到的响应是:

{"result": [["water", "None"], ["temp", "001"], ["temp", "002"], ["temp", "003"], ["temp", "004"], ["temp", "005"], ["temp", "006"], "id": "1", "jsonrpc": "2.0"}

如何在html页面的表格中显示这些数据?

【问题讨论】:

标签: html json angular html-table json-rpc


【解决方案1】:
<tr *ngFor="let i of json" >
      <td>
        <input type=text [(ngModel)]="i.result" >
     </td>
</tr>

这将在表中循环你的 json 数据,你应该根据需要更改循环数据 干杯..!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-22
    • 2013-03-09
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 2016-06-30
    相关资源
    最近更新 更多