【发布时间】: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页面的表格中显示这些数据?
【问题讨论】:
-
嗨@DaanSeuntjens 我是角度新手,你能更具体地在哪里实现这个吗?
-
其实我对 angularjs 也不熟悉,但是尝试在网上搜索如何解决这些问题。 F.e.搜索“angularjs json parsing”或“angularjs json tutorial example”等,你可能会找到你要找的东西
-
您的 json 格式无效。请检查一次好吗?
标签: html json angular html-table json-rpc