刚接触React现在遇到一个问题:
首先调用接口获取到了所有商品信息,然后再循环出每个商品显示出来,其中商品的类目是个Id,然后我要根据类目Id调用接口获取类目名称。现在我应该怎样做才能获取到这个类目名称?
const contextList=this.state.list.length
?
this.state.list.map((newlist,index)=>(
<tr className="context_tr2">
<td className="context_td1"><Checkbox /></td>
<td className="context_td2"> 已重发</td>
<td className="context_td4">
<span>所属类目:{this.queryCategory(newlist.categoryID)}</span>
</td>
</tr>
))
:
'无数据'
;
//查询类目
queryCategory=(categoryID)=>{
window.bridge.call('open.api.request', {
version: '1',
namespace: 'com.alibaba.product',
name: 'alibaba.category.get',
async:true,
data: {
webSite:"1688",
categoryID:categoryID
}
}, (res) => {
const categoryName =res.result.data.categoryInfo[0].name;
//这里可以得到类目名称,但我要怎么传出去呢?
});
return “”;
};
我用这种方法始终都不能把获取到的值 return出去。第一次使用React 不知道该怎么做?或者我的思路不对?求指点