Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用React映射数组_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript 如何使用React映射数组

Javascript 如何使用React映射数组,javascript,reactjs,react-native,Javascript,Reactjs,React Native,以下是我的React代码,其中我正在映射一个对象数组,但出现错误[应为赋值或函数调用,而不是看到表达式],因此请帮助我如何解决此问题。。? 在我的代码中,我想将数据映射到bootstrap 4旋转木马滑块代码,在我的数据中,我有照片、姓名、成就,所以如何映射其中的3个 import React, { useState, useEffect } from "react"; import web from "../../image/nisha.jpg"; im

以下是我的React代码,其中我正在映射一个对象数组,但出现错误[应为赋值或函数调用,而不是看到表达式],因此请帮助我如何解决此问题。。? 在我的代码中,我想将数据映射到bootstrap 4旋转木马滑块代码,在我的数据中,我有照片、姓名、成就,所以如何映射其中的3个

import React, { useState, useEffect } from "react";
import web from "../../image/nisha.jpg";
import web1 from "../../image/Pooja.jpg";
import web2 from "../../image/6547.jpg";
import { isAutheticated } from "../../auth/helper/index";
import { getTestis } from "../helper/coreapicalls";
import "../../styles.scss";
import ReactReadMoreReadLess from "react-read-more-read-less";

const Testimonial1 = () => {
  const [testimonial, setTestimonial] = useState([]);
  const [error, seterror] = useState([]);
  const [loading, setLoading] = useState(false);
  const token = isAutheticated() && isAutheticated().token;
  const userId = isAutheticated() && isAutheticated().user.email;

  useEffect(() => {
    loadTestimonial();
  }, []);

  const loadTestimonial = () => {
    getTestis().then((data) => {
      if (data.error) {
        seterror(data.error);
      } else {
        setTestimonial(data);
        console.log(data);
      }
    });
    setLoading(true);
  };
  console.log(testimonial);
  return (
    <div>
      <h1 className="blog_heading">Testimonials</h1>
      <div className="testimonial">
        <div
          id="carouselExampleSlidesOnly"
          className="carousel slide"
          data-ride="carousel"
        >
          <div className="carousel-inner active container">
            {testimonial.map((testi, index) => {
              <div className="carousel-item active" key={index}>
                <div className="testimonial_content">
                  <a href={web}>
                    <img
                      src={web}
                      alt="img"
                      className="rounded-circle img-fluid "
                    />
                  </a>
                  <h1>{testi.name}</h1>

                  <p>
                    <sup>
                      <i
                        className="fa fa-quote-left mr-2"
                        style={{ fontSize: "14px", color: "#ffca08" }}
                        aria-hidden="true"
                      ></i>
                    </sup>
                    <ReactReadMoreReadLess
                      charLimit={200}
                      readMoreText={"Read more ▼"}
                      readLessText={"Read less ▲"}
                      readMoreStyle={{ color: "#00ba74", fontSize: "15px" }}
                    >
                      {testi.achievement}
                    </ReactReadMoreReadLess>
                  </p>
                </div>
              </div>;
            })}
          </div>
        </div>
      </div>
    </div>
  );
};

export default Testimonial1;
import React,{useState,useffect}来自“React”;
从“../../image/nisha.jpg”导入web;
从“../../image/Pooja.jpg”导入web1;
从“../../image/6547.jpg”导入web2;
从“./../auth/helper/index”导入{IsAuthenticated}”;
从“./helper/coreapicalls”导入{getTestis};
导入“../../styles.scss”;
从“react READE more READLESS”导入REACTREADMOREADLESS;
常数证明1=()=>{
常量[推荐的,固定的]=useState([]);
const[error,seterror]=useState([]);
const[loading,setLoading]=useState(false);
const token=IsAuthenticated()&&IsAuthenticated().token;
const userId=isAuthenticated()&&isAuthenticated().user.email;
useffect(()=>{
加载证明();
}, []);
const loadEstimational=()=>{
getTestis()。然后((数据)=>{
if(data.error){
设置错误(data.error);
}否则{
时间(数据);
控制台日志(数据);
}
});
设置加载(真);
};
控制台日志(证明文件);
返回(
推荐书
{证明映射((证明,索引)=>{
{testi.name}

{测试成绩}

; })} ); }; 导出默认证明1;

只需将地图代码替换为:

testimonial.map((testi, index) => {
              return (
                     <div className="carousel-item active" key={index}>
                <div className="testimonial_content">
                  <a href={web}>
                    <img
                      src={web}
                      alt="img"
                      className="rounded-circle img-fluid "
                    />
                  </a>
                  <h1>{testi.name}</h1>

                  <p>
                    <sup>
                      <i
                        className="fa fa-quote-left mr-2"
                        style={{ fontSize: "14px", color: "#ffca08" }}
                        aria-hidden="true"
                      ></i>
                    </sup>
                    <ReactReadMoreReadLess
                      charLimit={200}
                      readMoreText={"Read more ▼"}
                      readLessText={"Read less ▲"}
                      readMoreStyle={{ color: "#00ba74", fontSize: "15px" }}
                    >
                      {testi.achievement}
                    </ReactReadMoreReadLess>
                  </p>
                </div>
              </div>;
              )
            })
estimonial.map((testi,index)=>{
返回(
{testi.name}

{测试成绩}

; ) })
您需要在映射函数homie中返回“请帮助我如何解决此问题…”-首先,您必须帮助我们。哪一行触发了错误,确切的错误消息是什么->第45:15行:预期是赋值或函数调用,但看到的却是一个表达式@andreaas,因为您可能已经注意到代码块中没有行号。不,我们不会数一数来找到正确的线…;){esticional.map((testi,index)=>{..}line@Andreashi,@kunal我在一张幻灯片上得到了我的所有数据更新@kunal panchal谢谢,请回答这个问题stackoverflow.com/q/66156615/15160538,@kunal