# @anypoint-web-components/anypoint-selector 中文文档

规范地址：https://npmcn.com/package/%40anypoint-web-components/anypoint-selector/

版本：1\.1\.8
npm 元数据更新时间：2026-04-07T19:25:24.047Z
中文译文更新时间：2026-11-06T12:06:08.376Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40anypoint-web-components/anypoint-selector
原文对照：https://npmcn.com/package/%40anypoint-web-components/anypoint-selector/?lang=original
项目主页：https://github.com/anypoint-web-components/anypoint-selector#readme
源码仓库：https://github.com/anypoint-web-components/anypoint-selector

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：101 kB，26 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- 运行依赖：3 个
- 首次发布：2019-08-03T22:30:52.538Z
- 最新版本发布：2021-08-27T13:55:17.548Z
- 近 30 天下载量：3285（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：11（近 12 个月 0 个）

## 中文简介

与ES6等相通的"铁选"口. 管理可以选择的元素列表.

## 安装

```sh
npm install @anypoint-web-components/anypoint-selector
```

也可以使用：`pnpm add @anypoint-web-components/anypoint-selector`、`yarn add @anypoint-web-components/anypoint-selector`、`bun add @anypoint-web-components/anypoint-selector`

## README

[![Published on NPM](https://img.shields.io/npm/v/@anypoint-web-components/anypoint-selector.svg)](https://www.npmjs.com/package/@anypoint-web-components/anypoint-selector)

[![Build Status](https://travis-ci.com/anypoint-web-components/anypoint-selector.svg)](https://travis-ci.com/anypoint-web-components/anypoint-selector)

[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/anypoint-web-components/anypoint-selector)

# 任意点选择器

这是港口 [铁选取器](https://github.com/PolymerElements/iron-selector) 与LitElement和ES6类合作,最初由Polymer团队开发.

## < 任意点选择器 > , `AnypointSelectableMixin`, (中文(简体) ), `AnypointMultiSelectableMixin`

`anypoint-selector` 是可用于管理可以选择的元素列表的元素. 点击此项目将选择该项目 。 这个 `selected` 表示所选择的项目. 默认使用项目索引. `anypoint-selector`函数完全由 `AnypointMultiSelectableMixin`。 。 。 .

`AnypointSelectableMixin` 给出选定儿童要素的概念。 默认情况下, 元素将选择其可选择的孩子之一 当一个点击事件被发送到它时.

`AnypointSelectableMixin` 让你...

-   确定哪些儿童应被视为可以选择的儿童(`selectable`, (中文(简体) ),
-   获取当前选中的元素( r)`selectedItem`)和所有要素 在可选集中(`items`, (中文(简体) ),
-   更改选择( e)`select`, (中文(简体) ), `selectNext`(例如),
-   决定如何修改选定的元素以显示其选定的状态(`selectedClass`, (中文(简体) ), `selectedAttribute`, (中文(简体) ),

...除了别的.

`AnypointMultiSelectableMixin` 包括: `AnypointSelectableMixin` 以及一个 `multi` 属性,可设置为 `true` 以表示该元素可以有多个选定的儿童元素. 它还包括: `selectedItems` 财务报告和审定财务报表 `selectedValues` 可选元素及其相应值的数组工作属性(`multi` 实值 `true`) - 类似于由以下人士提供的单个项目版本: `AnypointSelectableMixin`数字 : `selectedItem` 财务报告和审定财务报表 `selected`。 。 。 .

该元素没有自己的影子DOM. 项目按原样交付。 该元素还涵盖在另一个自定义元素中使用选择器的情况和 `<slot>` 以儿童身份通过(例如,在轻度DOM中定义的降入列表。).

## 使用量

### 安装

```
npm install --save @anypoint-web-components/anypoint-selector
```

### 在 html 文件内

```html
<html>
  <head>
    <script type="module">
      import '@anypoint-web-components/anypoint-selector/anypoint-selector.js';
    </script>
  </head>
  <body>
    <anypoint-selector selected="0">
      <div>Item 0</div>
      <div>Item 1</div>
      <div>Item 2</div>
      <div>Item 3</div>
      <div>Item 4</div>
    </anypoint-selector>
    <script>
    {
      document.querySelector('files-payload-editor').onselect = (e) => {
        console.log(e.detail.value);
      };
    }
    </script>
  </body>
</html>
```

### 在 LitElement 模板中

```javascript
import { LitElement, html } from 'lit-element';
import '@anypoint-web-components/anypoint-selector/anypoint-selector.js';

class SampleElement extends LitElement {
  render() {
    return html`
    <anypoint-selector @select="${this._selectedHandler}"></anypoint-selector>
    `;
  }

  _selectedHandler(e) {
    console.log('current selection:', e.detail.item);
  }
}
customElements.define('sample-element', SampleElement);
```

## 发展

```sh
git clone https://github.com/anypoint-web-components/anypoint-selector
cd anypoint-selector
npm install
```

### 本地运行演示

```sh
npm start
```

### 运行测试

```sh
npm test
```

## 常见问题

### @anypoint-web-components/anypoint-selector 是什么？

与ES6等相通的"铁选"口\. 管理可以选择的元素列表\.

### 如何安装 @anypoint-web-components/anypoint-selector？

在项目目录运行 npm install @anypoint-web-components/anypoint-selector，或使用 pnpm add / yarn add / bun add。

### @anypoint-web-components/anypoint-selector 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/anypoint-web-components\_\_anypoint-selector 是否存在。

### @anypoint-web-components/anypoint-selector 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @anypoint-web-components/anypoint-selector 可以商用吗？

@anypoint-web-components/anypoint-selector 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @anypoint-web-components/anypoint-selector 的下载量有多少？

根据 npm 官方下载统计，@anypoint-web-components/anypoint-selector 在 2026/10/06 – 2026/11/04 这 30 天内被下载 3,285 次，日均约 110 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @anypoint-web-components/anypoint-selector 还在维护吗？

最新版本 1\.1\.8 发布于 2021/08/27（5 年前）；至今共发布 11 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/08/04。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

