我试图从公共API中获取数据,然后显示React组件中的数据,react部分并不重要,这主要是一个js问题。为了学习,我使用创建了一个新对象,其中包含了请求中所需的数据,然后将该对象推送到调用时函数返回的数组中:
// fetchPoke() function
let pokemons = []
// IDs is just an array with 20 random numbers between a range
IDs.forEach(async (id) => {
let url = `https://pokeapi.co/ap
我的抓取有问题。我将API获取到我的项目中,当我试图在值上使用display时,它在第一次单击时就不起作用了。在第二次单击时,该函数将运行良好,一切正常。当im试图登录取取函数时,一切正常,但是,在显示函数上,我得到了一个错误:如果我编写了许多pokemon来搜索,然后单击搜索它不起作用,但是如果我更改它并再次单击它,我将得到第一个pokemon值。
Uncaught :无法读取未定义(读取“名称”)的属性
我添加了fetch的功能和显示功能,如果有人想帮忙的话,我也可以发送git存储库。德克斯
let fetetchPokemon = function (inputNum) {
我是一个新的开发者,正在学习如何使用API,现在我已经多次遇到这个错误,它不断地使Node崩溃: SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at IncomingMessage.<anonymous> (/Users/SA/Desktop/pokeApp/app.js:13:34)
at IncomingMessage.emit (events.js:314:20)
at IncomingMessage.Readable.read (_stream
我有一个名为move_dict的对象,正在使用get_learned_by_pokemon()方法来填充它。在getPokes()中,我调用get_learned_by_pokemon()并期望填充move_dict。但是它是空的。
function move(){
let move_dict = {}
let db_data = JSON.parse(fs.readFileSync('pokes.json', 'utf8'));
async function get_learned_by_pokemon(curr_move, move_
下面是我的减速机及其输出。结果很奇怪。变量actions.pokemons:是一个数组,每个元素都是一个对象。它的值分配给a,复制到b。我不明白为什么b是空数组。另外,返回值是一个空数组,状态不是更新吗?
const pokemons = (state=[], action) => {
switch(action.type){
case types.FETCH_POKEMON:
var a = action.pokemons
console.log(a)
var b = [...action.
对于如何将输入字段中的pokemon的名称添加到api的url中,我遇到了问题。我的目标是能够搜索所需的口袋妖怪,然后在下面的div中查看它。我不太确定为了实现这一点,这个特定的技术或方法会被调用什么。提前谢谢你。
<!DOCTYPE html>
<!-- Create a full CRUD application of your choice. If you can use an existing API, use AJAX to interact with it. However, you do not have to use an API. If you do not
我正试图了解单元测试是如何工作的,并且已经构建了一个小的React应用程序来呈现一个Pokemon列表。我要做的是编写一个单元测试,检查列表是否正确呈现。但是,生成的快照显示它只呈现“加载.”文本,这是它在等待API的响应时应该做的事情。我做错了什么?
PokemonList.test.js
import React from 'react';
import PokemonList from '../components/PokemonList';
import renderer from 'react-test-renderer';
desc
constructor(private pokedexApi:ApiPokemonsService) {
}
ngOnInit(): void {
this.getPokemons()
}
// instead of pokemon having an Id of the pokedex, is better to retrieve the data of that id to the pokemon attribute
getPokemons() {
// subscribing Api data from the this method
this.pokedexAp