使用游标(不工作)
Working with cursors (NOT WORKING)
我一直在关注 Working With Cursors here. I wondered , where is the appropriate file code location modules for this cursor tutorial. Let's say I want to reuse this tutorial module on People Pieces 上的教程。我在 people/index.js 上有这段代码。
module.exports = {
extend: 'apostrophe-pieces',
permissionsFields : true,
name: 'person',
label: 'Person',
pluralLabel: 'People',
addFields : [
{
name: 'firstName',
label: 'First Name',
type: 'string',
required: true,
},
{
name: 'lastName',
label: 'Last Name',
type: 'string',
required: true
},
{
name: 'title',
label: 'Full Name',
type: 'string',
required: true,
contextual: true
},
{
name: 'slug',
label: 'Slug',
type: 'string',
required: true,
contextual: true
},
{
name: 'body',
label: 'Biography',
type: 'area',
options: {
widgets: {
'apostrophe-rich-text': {
toolbar: ['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]
}
},
{
name: 'reputation',
label: 'Reputation',
type: 'integer'
}
],
arrangeFields: [{
name: 'contact',
label: 'Contact',
fields: ['firstName', 'lastName', 'phone']
},
{
name: 'admin',
label: 'Administrative',
fields: ['slug', 'published', 'tags']
},
{
name: 'content',
label: 'Biographical',
fields: ['thumbnail', 'body']
}
],
construct: function(self, options) {
self.beforeSave = function(req, piece, options, callback) {
// Override title and MUST SET CONTEXTUAL to able to save. Let the
// backend self.beforeSave method do this thing.
// You know why I don't set piece.slug ?
// Because once you already set title , apostrophe made it for you :)
// BUT must put contextual : true on slug. If not, it will prompt you :*
piece.title = piece.firstName + ' ' + piece.lastName;
return callback();
}
return self.apos.docs.getManager('person').find(req, {
reputation: {
$gte: 30
}
}).sort({
updatedAt: -1
})
.toArray(function (err, people) {
console.log(people);
});
}
};
它在控制台上输出这样的结果:
.find() is undefined
但是后来,我尝试在涉及 self.pushAsset 的浏览器端使用,仍然没有 console.log 任何东西!我知道我应该使用这些模式来遵循该教程。但是让我们对代码集思广益一段时间以便更好地理解。如果我重用我在 People Pieces 上所做的模式的代码怎么样?或者是否有任何特定要求或方法可用于 apos.getManager(piecesName) ?哦,顺便说一句,我也在 people-widget/index.js 上进行了试验,但它没有使用相同的错误输出进行锻炼。如果我不能遵循本教程,我将永远不会理解使用该代码。我喜欢 ApostropheCMS <3
我找到了答案。我还在我的终端控制台上解决了 req not defined
。
所以我在 app.js
中为游标做了这个。最后,它确实输出了这些东西。
'people-pages' : {
extend : 'apostrophe-pieces-pages',
construct: function (self, options) {
return self.apos.docs.getManager('person').find({
reputation: {
$gte: 30
}
}).toArray(function (err, people) {
console.log("List of peoples \n",people);
});
}
},
我一直在关注 Working With Cursors here. I wondered , where is the appropriate file code location modules for this cursor tutorial. Let's say I want to reuse this tutorial module on People Pieces 上的教程。我在 people/index.js 上有这段代码。
module.exports = {
extend: 'apostrophe-pieces',
permissionsFields : true,
name: 'person',
label: 'Person',
pluralLabel: 'People',
addFields : [
{
name: 'firstName',
label: 'First Name',
type: 'string',
required: true,
},
{
name: 'lastName',
label: 'Last Name',
type: 'string',
required: true
},
{
name: 'title',
label: 'Full Name',
type: 'string',
required: true,
contextual: true
},
{
name: 'slug',
label: 'Slug',
type: 'string',
required: true,
contextual: true
},
{
name: 'body',
label: 'Biography',
type: 'area',
options: {
widgets: {
'apostrophe-rich-text': {
toolbar: ['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]
}
},
{
name: 'reputation',
label: 'Reputation',
type: 'integer'
}
],
arrangeFields: [{
name: 'contact',
label: 'Contact',
fields: ['firstName', 'lastName', 'phone']
},
{
name: 'admin',
label: 'Administrative',
fields: ['slug', 'published', 'tags']
},
{
name: 'content',
label: 'Biographical',
fields: ['thumbnail', 'body']
}
],
construct: function(self, options) {
self.beforeSave = function(req, piece, options, callback) {
// Override title and MUST SET CONTEXTUAL to able to save. Let the
// backend self.beforeSave method do this thing.
// You know why I don't set piece.slug ?
// Because once you already set title , apostrophe made it for you :)
// BUT must put contextual : true on slug. If not, it will prompt you :*
piece.title = piece.firstName + ' ' + piece.lastName;
return callback();
}
return self.apos.docs.getManager('person').find(req, {
reputation: {
$gte: 30
}
}).sort({
updatedAt: -1
})
.toArray(function (err, people) {
console.log(people);
});
}
};
它在控制台上输出这样的结果:
.find() is undefined
但是后来,我尝试在涉及 self.pushAsset 的浏览器端使用,仍然没有 console.log 任何东西!我知道我应该使用这些模式来遵循该教程。但是让我们对代码集思广益一段时间以便更好地理解。如果我重用我在 People Pieces 上所做的模式的代码怎么样?或者是否有任何特定要求或方法可用于 apos.getManager(piecesName) ?哦,顺便说一句,我也在 people-widget/index.js 上进行了试验,但它没有使用相同的错误输出进行锻炼。如果我不能遵循本教程,我将永远不会理解使用该代码。我喜欢 ApostropheCMS <3
我找到了答案。我还在我的终端控制台上解决了 req not defined
。
所以我在 app.js
中为游标做了这个。最后,它确实输出了这些东西。
'people-pages' : {
extend : 'apostrophe-pieces-pages',
construct: function (self, options) {
return self.apos.docs.getManager('person').find({
reputation: {
$gte: 30
}
}).toArray(function (err, people) {
console.log("List of peoples \n",people);
});
}
},