Vue v-for嵌套數據渲染問題

Vue v-for嵌套數據渲染問題vue

問題描述:異步

因爲在獲取商品子分類的時候,同時須要獲取子分類下的商品,那麼多層的列表渲染就只能是第一層好用this

問題緣由:url

vue在處理多層的渲染的時候,不能直接用等號賦值出來的數據,只能是用官方提供的$set方法spa

解決辦法:code

在用異步請求數據的時候,返回的時候直接用$set方法給屬性賦值。blog

function ProductTypeSubList(Id) {
    var url = globalUtils.globalHomeUrl + urlConstants.Product.GetProTypeList + "?CustomerID=0&Id=" + Id;
    Vue.http.get(url)
        .then((response) => {
            if (response.data.Code == 0) {
                var ProListUrl = globalUtils.globalHomeUrl + urlConstants.Product.GetProList + "?CustomerID=0&ProTypeId=";
                var ProductTypeSubList = response.data.Data.L_ProTypeList;
                Assort.$set(Assort, "ProductTypeSubList", ProductTypeSubList);
                ProductTypeSubList.forEach(function(element) {
                    var ProList = new Array();
                    Vue.http.get(ProListUrl + element.Id)
                        .then((response) => {
                            if (response.data.Code == 0) {
                                Assort.$set(element, "ProList", response.data.Data.L_ProList);
                            }
                        });
                }, this);
            } else {
                Assort.$set(Assort, "ProductTypeSubList",  []);
            }
        });
}
相關文章
相關標籤/搜索