npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tingle-select-field

v0.2.2

Published

表单选择域

Downloads

10

Readme

tingle-select-field npm version

SelectField 是选择输入表单域。

Install

npm install tingle-select-field --save

Simple Usage

constructor(props) {
    super(props);
    this.state = {
        // 数据模型
        data: [
            [
                { value: 0, text: '一月' },
                { value: 1, text: '二月' },
                { value: 2, text: '三月' },
                { value: 3, text: '四月' },
                { value: 4, text: '五月' },
                { value: 5, text: '六月' },
                { value: 6, text: '七月' },
                { value: 7, text: '八月' },
                { value: 8, text: '九月' },
                { value: 9, text: '十月' },
                { value: 10, text: '十一月' },
                { value: 11, text: '十二月' }
            ]
        ],
        // 选中的值
        value: [ { value: 6, text: '七月' } ]
    };
}
handleChange(value) {
    // 数据确认变更
    this.setState({
        value: value
    });
}
render() {
    var t = this;
    return (
        <div>
            <SelectField label="下拉选择" data={t.state.data} onChange={t.handleChange.bind(t)} value={t.state.value}/>
        </div>
    );
}

Options 可用配置

| 配置项 | 必填 | 默认值 | 功能/备注 | |---|----|---|----| |className|optional|-|自定义样式类| |label|required|-|表单域名称| |placeholder|optional|-|提示文案| |confirmText|optional|完成|确认文案| |cancelText|optional|取消|取消文案| |data|optional|-|数据模型(注1)| |value|optional|-|选中数据(注2)| |readOnly|optional|false|是否只读| |onChange|optional|-|值变化触发的事件(注3)|

注1: data 是一个二维数组,第一维表示滚轮列,第二维表示各列中的选项。

每个选项必须包括 text(显示的文字) 和 value(选项的值) 属性。典型的格式如下:

[
    [
        {
            text: '江苏',
            value: 'jiangsu'
        },
        {
            text: '浙江',
            value: 'zhejiang'
        }
    ],
    [
        {
            text: '杭州',
            value: 'hangzhou'
        },
        {
            text: '宁波',
            value: 'ningbo'
        }
    ]
]

可以通过调用 SelectField.formatDataValue 来兼容其他的一些格式,详见 tingle-slot 的文档

注2: value 是一个一维数组,分别表示每一列的选中值。

数组中的元素一般为 data 中对应选项的引用,也可以通过 value 属性来和选项建立绑定。典型的格式如下:

[
    {
        text: '浙江',
        value: 'zhejiang'
    },
    {
        text: '杭州',
        value: 'hangzhou'
    }
]

可以通过调用 SelectField.formatDataValue 来兼容其他的一些格式,详见 tingle-slot 的文档

注3: onChange 参数为 value(当前选中值数组)

API 接口

SelectField.formatDataValue(data[, value])

datavalue 的非标准格式兼容,返回标准格式的 { data, value }

可以通过调用 SelectField.formatDataValue 来兼容其他的一些数据格式,详见 tingle-slot 的文档

SelectField.formatColumnValue(columnData[, columnValue])

替换单列的 data 和 value 时使用,兼容规则同上。

可以通过调用 SelectField.formatColumnValue 来兼容其他的一些数据格式,详见 tingle-slot 的文档

Links 相关链接