关于Schema.dynamic与动态展示数据的一些问题

我想在config加入一个列表,该列表的项数是可变的。我在使用Schema.dynamic过程中发现数据无法被正常展示到配置项里。想知道我在哪里出了问题。

config.ts

export interface Config {
  Items: array<MarketItem>
}
export const Config: Schema<Config> = Schema.intersect([
  Schema.object({
    Items: Schema.dynamic('Items'),
  }).description('商品列表'),

services.ts

         const schema = Schema.union(
            this.Items.map(item => Schema.object({
                id: Schema.const(item.id).required().default(item.id).description(item.name),
                name: Schema.const(item.name).required().default(item.name).description(item.description),
                price: Schema.const(item.price).required().default(item.price).description(`价格:${item.price}`),
                image: Schema.const(item.image).default(item.image).description(`图片:${item.image}`),
                tags: Schema.const(item.tags).default(item.tags).description(`标签:${item.tags}`),
                stock: Schema.const(item.stock).default(item.stock).description(`库存:${item.stock}`),
            })) 
        )
        this.ctx.schema.set('Items', schema)
1 个赞