【发布时间】:2021-08-18 22:17:12
【问题描述】:
我正在制作一个自定义 MS Teams 应用程序,并且在该应用程序中我试图从 url 获取 json 以便稍后显示内容。但是,获取失败。我的目标是从提供的 url 中获取数据列表,然后在我的团队应用程序的选项卡中显示它,这将是:Where i want my json content to show up
您可能会说,我根本没有任何 javascript 经验,但自定义 MS 团队应用程序需要 javascript...
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import React from 'react';
import './App.css';
import * as microsoftTeams from "@microsoft/teams-js";
/**
* The 'GroupTab' component renders the main tab content
* of your app.
*/
class Tab extends React.Component {
constructor(props){
super(props)
this.state = {
context: {}
}
}
//React lifecycle method that gets called once a component has finished mounting
//Learn more: https://reactjs.org/docs/react-component.html#componentdidmount
componentDidMount(){
// Get the user context from Teams and set it in the state
microsoftTeams.getContext((context, error) => {
this.setState({
context: context
});
});
// Next steps: Error handling using the error object
}
componentDidMount() {
fetch('http://example.com/movies.json')
.then(response => response.json())
.then(data => console.log(data));
}
render() {
var jsondata = data;
let userName = Object.keys(this.state.context).length > 0 ? this.state.context['upn'] : "";
return (
<div>
</div>
);
}
}
export default Tab;
总而言之,我如何从 url 获取我的 json 并在团队内的 tab.js 页面上显示该 json 的内容?
提前感谢您的帮助。
【问题讨论】:
标签: javascript reactjs fetch microsoft-teams