MCPcopy
hub / github.com/coderwhy/HYMiniMall / _getCategory

Function _getCategory

pages/category/category.js:22–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20 this._getCategory()
21 },
22 _getCategory() {
23 getCategory().then(res => {
24 // 1.获取categories
25 const categories = res.data.category.list;
26
27 // 2.初始化每个类别的子数据
28 const categoryData = {}
29 for (let i = 0; i < categories.length; i++) {
30 categoryData[i] = {
31 subcategories: [],
32 categoryDetail: []
33 // categoryDetail: {
34 // 'pop': [],
35 // 'new': [],
36 // 'sell': []
37 // }
38 }
39 }
40
41 // 3.修改data中的数据
42 this.setData({
43 categories: res.data.category.list,
44 categoryData: categoryData
45 })
46
47 // 4.请求第一个类别的数据
48 this._getSubcategory(0)
49
50 // 5.请求第一个类别的详情数据
51 this._getCategoryDetail(0)
52 })
53 },
54 _getSubcategory(currentIndex) {
55 // 1.获取对应的maitkey
56 const maitkey = this.data.categories[currentIndex].maitKey;

Callers

nothing calls this directly

Calls 1

getCategoryFunction · 0.90

Tested by

no test coverage detected