# Category-selector.js:73 - 未捕获的类型错误：this.attrs.onChange 不是一个函数

**URL:** <https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883>\
**Category:** Bug\
**Created:** [2023年十一月8日 23:59 UTC](https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883 "2023-11-08T23:59:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![KCAS](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@KCAS](https://meta.discourse.org/u/KCAS)\
**Post date:** [2023年十一月8日 23:59 UTC](https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883/1 "2023-11-08T23:59:55Z")

</div>

你好，

我们一直在顺利使用“discourse-categories-suppressed”，隐藏了两个类别。当我们选择第三个类别时，控制台中出现了此错误，并且选择器已损坏。我们可以重置类别，但现在无法设置任何类别，只会出现此错误。

版本 0.1。

有一点需要注意，在插件列表中也无法禁用它。已禁用所有其他插件，但错误仍然存在。

完整错误

```plaintext
vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18 Uncaught TypeError: this.attrs.onChange is not a function
    at e.onChange (chunk.7a74475b96755fa3ebfa.gz.js:1:3762101)
    at e._boundaryActionHandler (chunk.7a74475b96755fa3ebfa.gz.js:1:3827688)
    at chunk.7a74475b96755fa3ebfa.gz.js:1:3825926
    at vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:505747
    at new R (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:505815)
    at e._onChangeWrapper (chunk.7a74475b96755fa3ebfa.gz.js:1:3825496)
    at $._join (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:522420)
    at $.join (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:519242)
    at p (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:300802)
    at s.change (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:301007)
    at e.select (chunk.7a74475b96755fa3ebfa.gz.js:1:3797421)
    at e.select (chunk.7a74475b96755fa3ebfa.gz.js:1:3762049)
    at e.r [as select] (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:224119)
    at $._run (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:522580)
    at $._join (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:522379)
    at $.join (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:519242)
    at p (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:300802)
    at s.select (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:301007)
    at e.click (chunk.7a74475b96755fa3ebfa.gz.js:1:3853381)
    at e.trigger (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:245776)
    at e.r [as trigger] (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:224119)
    at e.trigger (chunk.7a74475b96755fa3ebfa.gz.js:1:2422680)
    at e.r [as trigger] (vendor.9e07dd0436aff8751322647cc975361e-0b8308ceb741824f018ebb7f7d43bfd39b0bc2e6767be3de2e9822c547d27118.gz.js:18:224119)
    at HTMLLIElement.o (chunk.7a74475b96755fa3ebfa.gz.js:1:2422929)

```

---

<div class="post-metadata">

**Author:** ![KCAS](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@KCAS](https://meta.discourse.org/u/KCAS)\
**Post date:** [2023年十一月9日 10:39 UTC](https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883/2 "2023-11-09T10:39:58Z")

</div>

可评分类别也受到影响，似乎任何带有“category\_list”下拉菜单的内容都已损坏。此外，主题标签下拉菜单也存在同样的错误。

---

<div class="post-metadata">

**Author:** ![KCAS](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@KCAS](https://meta.discourse.org/u/KCAS)\
**Post date:** [2023年十一月9日 12:43 UTC](https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883/3 "2023-11-09T12:43:41Z")

</div>

安全模式无法解决问题，禁用插件也无法解决。

大家有什么可以尝试的故障排除方法吗？

---

<div class="post-metadata">

**Author:** ![KCAS](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@KCAS](https://meta.discourse.org/u/KCAS)\
**Post date:** [2023年十一月9日 22:14 UTC](https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883/4 "2023-11-09T22:14:45Z")

</div>

这里似乎有一个类似的帖子。

> [@Render a component within a Widget. (Using select-kit components within plugin code)](https://meta.discourse.org/t/render-a-component-within-a-widget-using-select-kit-components-within-plugin-code/84462/25?page=2):
>
> Ah, I think this might help: - @onChange={{action @data.onChangeUpdateTagSet}}/\> + @onChange=@data.onChangeUpdateTagSet/\> When passing a ‘closure action’, there is no need for the (action helper (and in this case, I guess it actually breaks things)

它在这里中断了。

category-selector.js

actions: {  
onChange(values) {  
this.attrs.onChange(values.map(v =\> Category.findById(v)).filter(Boolean));  
return false;  
}  
}

我已经设法通过数字海洋 Discourse 镜像的新建干净版本复制了这一点。所以没有插件，只是在初始设置之后，所以这与插件无关，而是 Discourse 核心问题。

```plaintext
rsvp.js:23 Uncaught TypeError: this.attrs.onChange is not a function
    at e.onChange (category-selector.js:73:18)
    at e._boundaryActionHandler (select-kit.js:415:42)
    at select-kit.js:330:12
    at rsvp.js:459:1
    at new R (rsvp.js:915:1)
    at e._onChangeWrapper (select-kit.js:312:12)
    at $._join (index.ts:646:21)
    at $.join (index.ts:362:17)
    at p (index.js:156:1)
    at s.change (index.js:257:1)
    at e.select (multi-select.js:74:22)
    at e.select (category-selector.js:68:12)
    at e.r [as select] (index.js:383:1)
    at $._run (index.ts:665:23)
    at $._join (index.ts:640:19)
    at $.join (index.ts:362:17)
    at p (index.js:156:1)
    at s.select (index.js:257:1)
    at e.click (select-kit-row.js:91:20)
    at e.trigger (core_view.js:63:1)
    at e.r [as trigger] (index.js:383:1)
    at e.trigger (ember-events.js:138:30)
    at e.r [as trigger] (index.js:383:1)
    at HTMLLIElement.o (ember-events.js:203:39)
onChange @ category-selector.js:73
_boundaryActionHandler @ select-kit.js:415
(anonymous) @ select-kit.js:330
(anonymous) @ rsvp.js:459
R @ rsvp.js:915
_onChangeWrapper @ select-kit.js:312
$._join @ index.ts:646
$.join @ index.ts:362
p @ index.js:156
(anonymous) @ index.js:257
select @ multi-select.js:74
select @ category-selector.js:68
r @ index.js:383
$._run @ index.ts:665
$._join @ index.ts:640
$.join @ index.ts:362
p @ index.js:156
(anonymous) @ index.js:257
click @ select-kit-row.js:91
trigger @ core_view.js:63
r @ index.js:383
trigger @ ember-events.js:138
r @ index.js:383
o @ ember-events.js:203

```

---

<div class="post-metadata">

**Author:** ![KCAS](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@KCAS](https://meta.discourse.org/u/KCAS)\
**Post date:** [2023年十一月9日 22:23 UTC](https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883/5 "2023-11-09T22:23:53Z")

</div>

看起来是在这里引入的：[DEV: remove trivial `{{action}}` usages (#24278) · discourse/discourse@8250609 · GitHub](https://github.com/discourse/discourse/commit/82506096b79ae72902a7bee5a33956ebe7981427)

---

<div class="post-metadata">

**Author:** ![Drew-ART](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@Drew-ART](https://meta.discourse.org/u/Drew-ART)\
**Post date:** [2023年十一月9日 22:40 UTC](https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883/6 "2023-11-09T22:40:45Z")

</div>

我目前在全新的 Discourse 安装中也看到了这个错误，我刚刚才设置好。它阻止了管理员区域中某些下拉菜单的点击。

鉴于你比我早几分钟遇到这个问题，我猜测是最近的某个更新导致了这个问题。你找到的链接是两天前的，这很吻合。

我只在我的新设置中看到了这个 bug，在我其他的网站上都没有。

---

<div class="post-metadata">

**Author:** ![KCAS](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@KCAS](https://meta.discourse.org/u/KCAS)\
**Post date:** [2023年十一月9日 22:59 UTC](https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883/7 "2023-11-09T22:59:56Z")

</div>

> [@Drew-ART](#):
>
> 我只在我的新设置中看到此错误，而在我其他任何站点上都没有。

很高兴（某种程度上）我不是唯一遇到此问题的人。我的服务器也是几天前才搭建的，这是我的第一次设置。

似乎是最近搭建的。

---

<div class="post-metadata">

**Author:** ![cvx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cvx/32/152146_2.png) [@cvx](https://meta.discourse.org/u/cvx)\
**Post date:** [2023年十一月9日 23:06 UTC](https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883/8 "2023-11-09T23:06:07Z")

</div>

应该已通过以下方式修复：

> <https://github.com/discourse/discourse/pull/24318>
>
> These were broken following 8250609, this gets them working again

（感谢 @awesomerobot！）

---

<div class="post-metadata">

**Author:** ![Drew-ART](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@Drew-ART](https://meta.discourse.org/u/Drew-ART)\
**Post date:** [2023年十一月10日 01:28 UTC](https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883/9 "2023-11-10T01:28:43Z")

</div>

感谢 @awesomerobot。我们预计何时能看到修复程序部署到我们的网站？

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [2023年十一月10日 08:33 UTC](https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883/10 "2023-11-10T08:33:06Z")

</div>

看起来它已经被合并了，所以更新你的网站应该可以获取到。👍

---

<div class="post-metadata">

**Author:** ![KCAS](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@KCAS](https://meta.discourse.org/u/KCAS)\
**Post date:** [2023年十一月10日 11:14 UTC](https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883/11 "2023-11-10T11:14:53Z")

</div>

已修复并解决！谢谢你

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2023年十一月12日 22:27 UTC](https://meta.discourse.org/t/category-selector-js-73-uncaught-typeerror-this-attrs-onchange-is-not-a-function/284883/12 "2023-11-12T22:27:47Z")

</div>


