0

Pieces 教程中的以下代码片段(http://apostrophecms.org/docs/tutorials/getting-started/reusable-content-with-pieces.html)给出了类型错误:self[name] is not a function -在 lib/modules/apostrophe-docs/lib/cursor 的第 1031 行。

单击保存按钮以添加新人或保存作品时会发生错误。

我知道这可能会发生,因为该对象实际上并不是我想的那样,或者因为它返回了一个空值。两者似乎都不太可能。

当我一步一步地按照教程进行操作时,我只浏览了光标部分。

people.index.js 文件如下:

module.exports = {
    extend: 'apostrophe-pieces',
    name: 'person',
    label: 'Person',
    pluralLabel: 'People',
    addFields: [
        {
            name: 'title',
            label: 'Full Name',
            type: 'string',
            required: true,
            contextual: true
        },
        {
            name: 'firstName',
            label: 'First Name',
            type: 'string',
            required: true
        },
        {
            name: 'lastName',
            label: 'Last Name',
            type: 'string',
            required:true
        },
        {
            name: 'body',
            label: 'Biography',
            type: 'area',
            options: {
                widgets: {
                    'apostrophe-rich-text': {
                        controls: [ 'Bold', 'Italic', 'Link', 'Unlink' ]
                    },
                    'apostrophe-images': {}
                }
            }
        },
        {
            name: 'phone',
            label: 'Phone',
            type: 'string'
        },
        {
            name: 'thumbnail',
            label: 'Thumbnail',
            type: 'singleton',
            widgetType: 'apostrophe-images',
            options: {
                limit: 1,
                minSize: [ 200, 200 ],
                aspectRatio: [ 1, 1 ]
            }
        }
    ],
    arrangeFields: [
        {
            name: 'contact',
            label: 'Contact',
            fields: [ 'firstName', 'lastName', 'phone' ]
        },
        {
            name: 'admin',
            name: 'Admin',
            fields: [ 'slug', 'published', 'tags' ]
        },
        {
            name: 'content',
            name: 'Biographical',
            fields: [ 'thumbnail', 'body' ]
        }
    ],
    construct: function(self, options) {
        var superPushAssets = self.pushAssets;
        self.pushAssets = function() {
          superPushAssets();
          self.pushAsset('stylesheet', 'always', { when: 'always' });
        };
    },
    construct: function(self, options) {
        self.beforeSave = function(req, piece, options, callback) {
          piece.title = piece.firstName + ' ' + piece.lastName;
          return callback();
        };
    }
};
4

0 回答 0