Git Product home page Git Product logo

simple-sku's Introduction

Simple-SKU

npm version MIT Licence

用于商城商品的简易SKU模块。

安装

NPM或其它包管理器

npm install simple-sku

Script引入

<script src="/node_modules/simple-sku/build/index.umd.js"></script>

使用示例

ES6

import Sku from "simple-sku";

const sku = new Sku({
    items: { // 商品sku数据(自行格式化)
        42: "1_14_77",
        43: "1_14_78",
        44: "1_14_79",
        45: "1_15_77",
        46: "2_14_77",
        47: "3_14_77",
        48: "3_14_79",
        49: "3_18_78"
    },
    callback: (unavailable, skuId) => {
        // 操作回调
    }
});

sku.set(1, 15); // 设置选中

sku.unset(1); // 取消选中

ES5/Script引入

var sku = new Sku({
    items: { // 商品sku数据(自行格式化)
        42: "1_14_77",
        43: "1_14_78",
        44: "1_14_79",
        45: "1_15_77",
        46: "2_14_77",
        47: "3_14_77",
        48: "3_14_79",
        49: "3_18_78"
    },
    callback: function(unavailable, skuId) {
        // 操作回调
    }
});

sku.set(1, 15); // 设置选中

sku.unset(1); // 取消选中

Classes

Options

  • items: 商品规格数据(格式:{skuID:“第一层_第二层_第三层_第四层”},层级选项值为-1表示这层不可选)
  • depth: 层级深度(不传或传0则自动计算)
  • callback: 回调函数(第一个参数是不可选的合集,第二个参数是匹配的SkuId)

Methods

  • set: 设置选中(第一个参数是层级下标,第二个参数是选中值)
  • unset: 取消选中(参数是层级下标)

simple-sku's People

Contributors

pecasha avatar

Watchers

 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.