如何允许删除撇号数组对象中的数组项

How to allow deleting of array items in Apostrophe array object

我有一个建立在 Apostrophe-CMS 之上的相当广泛的网站,大量使用对象模式和管理编辑器界面。很长一段时间以来,我一直遇到数组问题,而且我一直无法弄清楚发生了什么。这似乎发生在我定义的每个数组中,但这是一个具体示例(这是 apostrophe-users 上添加的字段):

{
name: 'subscriptions',
label: 'Memberships',
type: 'array',
titleField: 'subscriptionYear',
schema: [
    {
        name: '_subscription',
        withType: 'subscription-type',
        type: 'joinByOne',
        idField: 'subscriptionId',
        filters: {
            projection: {
                type: 1,
                name: 1,
                description: 1,
                agreement: 1,
                familyMembers: 1,
                title: 1,
                _allowedGroup: 1,
                allowedGroupId: 1,
                price: 1
            }
        }
    },
    {
        name: 'expirationDate',
        label: 'Expiration Date',
        type: 'date',
        required: false
    },
    {
        name: 'waiverSignature',
        label: 'Waiver Signature',
        type: 'string',
        readOnly: true
    },
    {
        name: '_payment',
        withType: 'payments',
        type: 'joinByOne',
        idField: 'paymentId',
        titleField: 'subscriptionType',
        filters: {
            projection: {
                paymentDate: 1,
                userEmail: 1,
                paymentAmount: 1,
                subscriptionType: 1,
                subscriptionYear: 1,
                receiptEmail: 1
            }
        }
    },
    {
        name: 'familyMembers',
        label: 'Family Members',
        type: 'array',
        titleField: 'familyMemberName',
        schema: [
            {
                name: 'familyMemberName',
                label: 'Family Member Name',
                type: 'string'
            },
            {
                name: 'familyMemberBirthDate',
                label: 'Family Member Birth Date',
                type: 'date'
            }
        ]
    }
]
}

我 运行 遇到的问题是,除非您先保存对象,否则无法从此数组中删除项目。如果我尝试在不先保存用户的情况下从数组中删除一个项目,则该条目会在列表中闪烁(消失并几乎立即重新出现)。没有控制台错误。但是,如果我打开用户,保存用户(即使没有进行任何更改),然后在不关闭用户片段列表的情况下再次打开用户,我可以从数组中删除项目并再次保存。知道为什么会发生这种情况吗?

谢谢!

Is there a good place to put code to add an ID to a piece's array if it doesn't already have one?

最终问题似乎与在代码中创建数组值有关。添加 ID 的最佳位置是首次添加该值时。有一个撇号实用方法 self.apos.utils.generateId() 可用于此目的。如果您要在 Apostrophe 之外的某处添加值,cuid or uuid 实用程序可以提供帮助(Apos 方法使用 cuid)。