我正在尝试使用电影数据库中的多个数据对象Promise.all.在我遍历fetch调用的所有结果并使用.json()每一位数据后,我尝试将其记录到控制台.但是,我得到的是一个数组,而不是带有数据的对象数组Promises.嵌套在promises中,我可以看到我的数据,但我显然错过了一个步骤,以便拥有一组数据对象,而不仅仅是Promises.
我在这里错过了什么?
//store movie API URLs into meaningful variables
const trending = `https://api.themoviedb.org/3/trending/all/day?api_key=${API_KEY}`;
const topRated = `https://api.themoviedb.org/3/movie/top_rated?api_key=${API_KEY}&language=en-US&page=1`;
const nowPlaying = `https://api.themoviedb.org/3/movie/now_playing?api_key=${API_KEY}&language=en-US&page=1`;
const upcoming = `https://api.themoviedb.org/3/movie/upcoming?api_key=${API_KEY}&language=en-US&page=1`;
//create an array of urls to fetch data from
const allMovieURLs = [trending, topRated, nowPlaying, upcoming];
const promiseURLs = allMovieURLs.map(url => fetch(url));
Promise.all(promiseURLs)
.then(responses => responses.map(url => url.json()))
.then(dataArr => console.log(dataArr));
};
Run Code Online (Sandbox Code Playgroud) 单击我的按钮生成内容后,我尝试在我的 flex-container 上使用以下内容,但是当我调整窗口大小时,它会不断调整我的项目大小。我希望它们具有固定的宽度和高度(理想情况下,每个项目都是 100x100 像素的正方形)
flex-shrink: 0;
flex-grow: 0;
Run Code Online (Sandbox Code Playgroud)
flex-shrink: 0;
flex-grow: 0;
Run Code Online (Sandbox Code Playgroud)
const sampleContent = ["stuff1", "stuff2", "stuff3", "stuff4", "stuff5"]
const button = document.querySelector(".content");
const rootElement = document.querySelector("#root");
const widthDiv = document.querySelector("#width-value");
const resultContainer = document.querySelector("#root");
const widthValue = window.getComputedStyle(resultContainer, null).getPropertyValue("width");
button.addEventListener("click", () => {
sampleContent.forEach((content) => {
const newDiv = document.createElement("div");
console.log(newDiv);
newDiv.textContent = content;
newDiv.classList.add("result");
rootElement.appendChild(newDiv);
})
})
widthDiv.textContent = widthValue;Run Code Online (Sandbox Code Playgroud)
.result-container {
display: flex;
width: 60%;
height: 200px;
border: 1px black solid;
flex-wrap: nowrap;
}
.container …Run Code Online (Sandbox Code Playgroud)我从 Material UI 中复制并粘贴了一段非常简单的代码,我试图将其与 Typescript 一起使用。我有一个MediaCard组件(重命名为DisplayCard)。
当我编译代码时,我收到此错误:(34,23): Value must be set for boolean attributes。
我在弄清楚这个错误的根源时遇到了一些困难,因为我不确定需要设置哪个属性值......
这是代码:
应用程序.tsx
import * as React from "react";
import DisplayCard from "./components/DisplayCard";
const App = () => {
return <DisplayCard />;
};
export default App;
Run Code Online (Sandbox Code Playgroud)
显示卡.tsx
import * as PropTypes from "prop-types";
import * as React from "react";
import { createStyles, withStyles } from "@material-ui/core/styles";
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import CardActionArea from "@material-ui/core/CardActionArea";
import CardActions …Run Code Online (Sandbox Code Playgroud)