Technology Sharing

The problem of specification parameters not being displayed when publishing products on GuLi Mall P85

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

P85: After publishing a product and clicking Next, it is found that the specification parameters are not displayed

Open the console and find that the error forEach... error

After checking the cause of the problem, I found that the associated attributes of individual groups in the returned grouping (attrs) may be null

So at this time, you need to ensure that the attrs returned by the backend cannot be null

Method 1: Backend filtering: In the backend implementation class, determine and remove groups with attrs being null.

  1. **
  2. * 根据分类id查出所有分组和分组属性
  3. * @param catelogId
  4. * @return
  5. */
  6. @Override
  7. public List<AttrGroupWithAttrsVo> getAttrGroupWithAttrsByCatelogId(Long catelogId) {
  8. //获得在属性分组表中的所有属于当前分类的实体
  9. List<AttrGroupEntity> attrGroupEntities = this.list(new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId));
  10. List<AttrGroupWithAttrsVo> collect = attrGroupEntities.stream().map((group) -> {
  11. AttrGroupWithAttrsVo attrsVo = new AttrGroupWithAttrsVo();
  12. BeanUtils.copyProperties(group,attrsVo);
  13. //当前分组下的所有属性(没有"valueType": 0,)
  14. List<AttrEntity> attr = attrService.getRelationAttr(attrsVo.getAttrGroupId());
  15. attrsVo.setAttrs(attr);
  16. if ( attr!=null){
  17. return attrsVo;
  18. }
  19. return null;
  20. }).collect(Collectors.toList());
  21. collect.removeIf(Objects::isNull);
  22. return collect;
  23. }

Method 2: Add if judgment to the front-end page.showBaseAttrs()Methodfor eachAdd one in frontIf judgment

if (item.attrs != null && item.attrs.length > 0)