在插件中如何配置数组对象。我尝试了json_schema,但是对象属性配置无法使用 category 这类选择器,只能输入文本。而 type: objects 则根本无法在插件配置中工作。
json_schema 的配置
quectel_online_customer_category_customers:
default: "[]"
client: true
json_schema: QuectelOnlineCustomer::SiteSettings::CategoryCustomersJsonSchema
plugins/quectel-online-customer/lib/quectel_online_customer/site_settings/category_customers_json_schema.rb
# frozen_string_literal: true
module QuectelOnlineCustomer
module SiteSettings
class CategoryCustomersJsonSchema
def self.schema
@schema ||= begin
{
type: "array",
uniqueItems: true,
default: [],
items: {
type: "object",
title: "类别客服配置",
additionalProperties: false, # 禁止提交未定义字段
required: %w[category customers], # 两个字段必填
properties: {
category: {
type: "category",
description: "绑定的论坛分类",
label: "分类"
},
customers: {
type: "usernames", # 多选用户,替代单用户名username
description: "分配至该分类的客服账号,支持多选",
label: "客服用户",
}
}
}
}
end
end
end
end
end
是的,确实可以。但是type:objects里面也不支持 type:category,我的需求是想选择类别和群组。
我明白了,所以对象设置是直接添加到你的 settings.yml 中的,你需要这样格式化:
oauth2_category_example:
type: objects
default: []
area: "oauth2"
schema:
name: category_rule
identifier: name
properties:
name:
type: string
required: true
label: 规则名称
description: 此规则的标签
category:
type: categories
required: true
label: 类别
description: 此规则适用的类别
validations:
max: 1
groups:
type: groups
label: 组
description: 与此类别关联的组
这将生成一个如下所示的类别下拉菜单
按照这个配置
quectel_online_customer_category_customer_group:
type: objects
default: []
schema:
name: "类别客服分组"
identifier: name
properties:
name:
type: string
required: true
label: 名称
description: 名称
category:
type: categories
required: true
label: "类别"
description: "类别名称,请在 <a href=\"/categories\" target=\"_blank\">所有类别</a> 页面查看"
group_name:
type: groups
required: true
label: "客服分组名称"
description: "客服分组名称,英文字符,请在 <a href=\"/admin/groups\" target=\"_blank\">客服分组</a> 页面查看"
我遇到下面的错误:
Error occurred:
- While rendering:
{{outlet}} for -top-level
-top-level
{{outlet}} for application
application
DiscourseRoot
{{outlet}} for admin
admin
{{outlet}} for admin.schema
schema
SchemaSettingNewEditor
SchemaSettingField
SchemaSettingTypeCategories
CategorySelector
section-link.gjs:149
Attempted to rerender, but the Ember application has had an unrecoverable error occur during render. You should reload the application after fixing the cause of the error.
categories.gjs:13
Uncaught (in promise) TypeError: this.args.value?.map is not a function
at SchemaSettingTypeCategories.<anonymous> (categories.gjs:13:9)
跟我的版本有关系吗?
Discourse v2026.1.4 — Commits · discourse/discourse · GitHub — Ember v6.6.0
您是否在设置中保存了过时的配置?如果出现了重置按钮,能否尝试将其重置为默认设置?