跳到正文
Skillpedia
网站与界面(前端)29k · #9812

table-state

它能做什么

这项技能解释如何在 Ember 应用中,把表格设置(例如当前页)保存在 tracked 属性中。适合希望这些设置与模板保持同步的开发者。

适用场景

  • ✓当模板必须显示当前页或其他表格设置的时候。
  • ✓当按钮需要更改表格的某项设置,例如页码的时候。
  • ✓当表格设置变化后,屏幕上没有更新的时候。

技能链接

https://github.com/TanStack/table/blob/main/packages/ember-table/skills/table-state/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/TanStack/table/blob/main/packages/ember-table/skills/table-state/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“如何让我的 Ember 表格的“下一页”按钮在屏幕上更新页码?”

每周 5 个新技能,1 分钟读完。

工作原理

它展示如何把分页设置保存在 tracked 属性中,将其传给表格,并通过回调进行更新。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Load intent load @tanstack/table-core#table-state first for shared ownership, initialization, updater, and reset rules.

Glimmer tracks Table APIs, atom reads, and store-property reads inside template-consumed getters. A value cached outside tracked consumption is only a snapshot. There is no table.Subscribe or selector argument to useTable; table.store.subscribe is intentionally a no-op and cannot drive rendering.

Controlled tracked setup

import Component from '@glimmer/component'
import { tracked } from '@glimmer/tracking'
import { on } from '@ember/modifier'
import {
  rowPaginationFeature,
  tableFeatures,
  useTable,
  type PaginationState,
} from '@tanstack/ember-table'

const features = tableFeatures({ rowPaginationFeature })
const columns = [{ accessorKey: 'name' }]
const data = [{ name: 'Ada' }]

export default class PageStatus extends Component {
  @tracked pagination: PaginationState = { pageIndex: 0, pageSize: 10 }
  table = useTable(this, () => ({
    features,
    columns,
    data,
    state: { pagination: this.pagination },
    onPaginationChange: (next) => {
      this.pagination =
        typeof next === 'function' ? next(this.pagination) : next
    },
  }))

  get pageNumber() {
    return this.table.atoms.pagination.get().pageIndex + 1
  }

  nextPage = () => this.table.nextPage()

  <template>
    <button type='button' {{on 'click' this.nextPage}}>Page
      {{this.pageNumber}}</button>
  </template>
}

Reactive boundaries

  • Read tracked values inside the options thunk and assign callback results back to their tracked owner. Mutating this.pagination.pageIndex++ does not notify the thunk.
  • features and atoms are construction-time inputs. Updating ordinary live options does not replace the feature set or atom owners; create them once before useTable.
  • Pass the component as the owner for lifecycle cleanup when external atoms are used. The standalone one-argument thunk form remains supported.
  • Use the adapter's createAtom for external Glimmer-reactive ownership. Read it in a tracked getter and use feature APIs or the external atom to write.
  • Keep features, columns, and data stable. Call receiver-dependent methods through getters or helpers rather than passing extracted methods to templates.

Read for the task

For advanced reactive boundaries, shared atoms, or detailed subscription examples, read reactivity. For construction or rendering setup, read getting-started.

API discovery

Inspect node_modules/@tanstack/ember-table/declarations/index.d.ts, use-table.d.ts, signal.d.ts, and FlexRender.d.ts. Core feature APIs are in node_modules/@tanstack/table-core/dist/features/.

常见问题

为什么在模板之外读取的值不更新?

在 tracked 消费之外缓存的值只是快照,不会自行刷新。

Ember 中有 Subscribe 组件吗?

没有,这项技能说明没有 Subscribe 组件,store 订阅也不会驱动渲染。

我仍然可以在代码中读取当前页吗?

可以,你可以在模板使用的 getter 中读取它。

详情

作者的原始描述

Read and control Table v9 state in ember. Use for tracked reads, subscriptions, controlled slices, and framework-specific reactive boundaries.

repo: TanStack/table

热度

GitHub 星标
29k
排名
#9812
许可证
MIT
更新时间
2026/10/21

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能