【发布时间】:2021-06-20 08:00:57
【问题描述】:
我正在使用烧瓶和 ionic(angular) 创建一个应用程序,并且我正在尝试返回列表的 JSON 目前我的python代码如下
def get-stocks():
# Select all stocks
cursor.execute("""SELECT * FROM `tbl_symbol_index`""")
stocks = cursor.fetchall()
stockList = []
data = {}
for stock in stocks:
symbol = stock[0]
companyName = stock[1]
stockList.append({
"symbol": symbol,
"companyName": companyName
})
data = {'stocks': stockList}
print(len(data["stocks"]))
return jsonify(data)
这将返回以下字典。
data = {"stocks": [
"Symbol": "TSLA",
"companyName": "Tesla Inc"
],
[
"Symbol": "MSFT",
"companyName": "Microsoft"
],
[
"Symbol": "AAPL",
"companyName": "Apple"
],
}
我使用 Angular 从我的角度调用该函数
ngOnInit() {
// Get a list of all existing stocks
const Stocks = this.initializeItems();
}
async initializeItems(){
this.http.get("http://127.0.0.1:5000/get-stocks").subscribe(function(data) {
})
}
但由于某种原因,我无法在我的 HTML 中循环遍历它
<ion-list>
<ion-item *ngFor="let data of Stocks | filter:filterTerm">
<ion-label>{{data.symbol}}</ion-label>
<ion-label>{{data.companyName}}</ion-label>
</ion-item>
</ion-list>
【问题讨论】:
标签: html angular typescript ionic2