嵌套API调用的数据不会在响应中的组件中呈现

时间:2016-08-28 06:24:46

标签: reactjs reactjs-flux axios

我正在使用flux和axios对API调用做出反应,我已经实现了嵌套的API调用,我正在从API中正确地获取数据并且它在控制台中正确显示我,但问题是嵌套的API调用数据未在组件中呈现,这是我的代码

loadCategoryProducts(action) {

    axios.post(API, {
         "query": 'query {ProductListQuery(category :"'+action.params.category+'", subcategory :"'+action.params.subcategory+'"){productinfo{partterminologyid,aliasname,partterminologyname,usedescription,categoryname,subcategoryname}worldpacinfo{worldpaccategoryid,basevehicleidnumber,parttypeidnumber,branddescription,detaileddescription,Note,popularity,price,productimageurl,productpartnumber,productthumburl,ThumbURL,available,Part}}}',
    }).then(resp => {
        if(resp.data.data){
            var productsArr = resp.data.data['ProductListQuery'];
            var count = productsArr.length;
            productsArr.map(function(value, index) {
                if(value.worldpacinfo.basevehicleidnumber!='undefined') {
                    axios.post(API, {
                        "query": 'query {PriceQuery(basevehicleidnumber :"'+value.worldpacinfo.basevehicleidnumber+'",parttypeidnumber:"'+value.worldpacinfo.parttypeidnumber+'",productpartnumber:"'+value.worldpacinfo.productpartnumber+'"){corefee,retailprice}}',
                    }).then(resp1 => {
                        value.worldpacinfo['retailprice']=resp1.data.data.PriceQuery.retailprice;
                        value.worldpacinfo['corefee']=resp1.data.data.PriceQuery.corefee;
                    }).catch((err) => {
                        console.log(err);
                    });
                }
            })
        }
        //console.log(productsArr);
        this.product = productsArr;
        this.emit("change");
    }).catch((err) => {
            console.log(err);
    });
}

我在componentWillMount

中存储了这个方法

0 个答案:

没有答案