Javascript 迭代映射并在方法Reactjs中传递值

Javascript 迭代映射并在方法Reactjs中传递值,javascript,reactjs,typescript,Javascript,Reactjs,Typescript,我必须迭代这个details数组,并将id、name和designation传递给该方法 interface State { details: Array<{ id: string; name: string; designation: string; }>; 而不是this.props.id、this.props.name、this.props.designation。我想通过迭代details数组来传递其中的值。谁能知道怎么做!我试图通过在方法本身内部编

我必须迭代这个details数组,并将id、name和designation传递给该方法

interface State {
  details: Array<{
    id: string;
    name: string;
designation: string;
  }>;
而不是this.props.id、this.props.name、this.props.designation。我想通过迭代details数组来传递其中的值。谁能知道怎么做!我试图通过在方法本身内部编写map函数来实现这一点,但它迭代了数组中存在的值的次数:

interface State {
  details: Array<{
    id: string;
    name: string;
designation: string;
  }>;
sampleItemOne = () => {
    this.state.details.map((item) => {
     if(item) {
    this.productService
      .publishProduct(
        item.id,
        item.name,
        item.designation
      )
      .then((response) => {      
      })
      .catch((error) => {
        console.log(error);
      })
  }
    });
  };

我不确定这是否是您想要的,但这里有一个尝试:

interface State {
  details: Array<{
    id: string;
    name: string;
designation: string;
  }>;
sampleItem = (id, name, designation) => {
    this.sampleService
      .sampleMethod(id, name,designation)
      .then((response) => {
      })
      .catch((error) => {
        console.log(error);
      });
    };
还有,你要做的是:

interface State {
  details: Array<{
    id: string;
    name: string;
designation: string;
  }>;
this.state.details.map(item => this.sampleItem(item,id, item.name, item.designation))

你能提供一些更多的信息,比如从哪里调用这个方法,以及如何访问状态信息吗?我试图从表中调用这个方法。所以在表中我有不同的行,这就是为什么它调用的行数是行数的多次。您需要在表外调用此方法,因为我认为此方法会将数据馈送到表中以呈现行,对吗?我无法将此方法保留在表外!因为这个功能需要在表中执行。那么我想你需要提供更多关于文件的上下文,因为我们不能不看到你试图实现的代码。