Giter VIP home page Giter VIP logo

sku_graph's Introduction

SKU_Graph

一个使用图数据结构来计算商品规格可选项的项目

示例

// 假设有如下商品规格数据
  const specList = [
    {
      id: 1,
      name: 'Color',
      list: [
        { id: 1, name: '红' },
        { id: 2, name: '绿' },
      ],
    },
    {
      id: 2,
      name: 'Size',
      list: [
        { id: 3, name: '32G' },
        { id: 4, name: '128G' },
      ],
    },
    {
      id: 3,
      name: 'Model',
      list: [
        { id: 5, name: '套餐一' },
        { id: 6, name: '套餐二' },
      ],
    },
  ];
  const skuSpecCombines =  [
    [
      { id: 1, name: '红' },
      { id: 3, name: '32G' },
      { id: 5, name: '套餐一' },
    ],
    [
      { id: 1, name: '红' },
      { id: 4, name: '128G' },
      { id: 6, name: '套餐二' },
    ],
    [
      { id: 2, name: '绿' },
      { id: 3, name: '32G' },
      { id: 6, name: '套餐二' },
    ],
  ];

  // 实例化一个graph
  const graph = new SpecGraph(specList.map(({list}) => (list)), combine);

  // 传入已被选中的规格id
  const options = graph.getSpecOptions([1, 3])
  console.log(options) // [{ id: 2, name: '绿' }, { id: 4, name: '128G' }, { id: 5, name: '套餐一' },]

sku_graph's People

Contributors

chu2508 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.