是否可以在onBeforeAction或類似鉤子中更改(爲每個記錄添加更多字段)返回的集合?在onBefore鉤子或類似鉤子中更改返回的集合
我有InvoiceHistory集合,我通過分頁。我還想在每張發票中顯示公司名稱,公司地址,電子郵件地址和增值稅登記號碼 - 這四個字段存儲在另一個收藏中。所以我想將這四個字段添加到從InvoiceHistory返回的每個記錄中。如果還有其他方法可以做到這一點,我樂於接受建議。當您導航/瀏覽/翻頁到第二頁時,我正在使用Alethes meteor分頁,它丟失了itemTemplate中返回的幫助字段。 Alethes分頁還依賴於鐵路由器,是否有可能通過鐵路路由器實現我想要的功能
===================== ================================================== =
@Sean。謝謝。下面是使用流星發佈複合代碼:
if (Meteor.isServer) {
\t import { publishComposite } from 'meteor/reywood:publish-composite';
\t publishComposite('invoicesWithCompanyDetails', function(userId, startingDate,endingDate) {
\t \t return {
\t \t \t find() {
\t \t \t \t // Find purchase history for userId and the two dates that were entered. Note arguments for callback function
\t \t \t \t // being used in query.
\t \t \t \t return PurchaseHistory.find({Id:userId,transactionDate:{$gte:new Date(decodeURIComponent(startingDate)),
\t \t \t \t \t $lt:new Date(decodeURIComponent(endingDate))}});
\t \t \t },
\t \t \t children: [
\t \t \t \t {
\t \t \t
\t \t \t \t \t find() {
\t \t \t \t \t \t return CompanySharedNumbers.find(
\t \t \t \t \t \t \t { _id:"firstOccurrence" },
\t \t \t \t \t \t \t { fields: { companyName: 1, companyAddress: 1 } }
\t \t \t \t \t \t);
\t \t \t \t \t }
\t \t \t \t }
\t \t \t ]
\t \t }
\t });
}
Router.route('/store/invoices/:_username/:startingDate/:endingDate', { //:_startingDate/:_endingDate
\t name: 'invoices',
\t template: 'invoices',
\t onBeforeAction: function()
\t {
\t \t ...
\t },
\t waitOn: function() {
\t \t var startingDate = this.params.startingDate;
\t \t var endingDate = this.params.endingDate;
\t \t return [Meteor.subscribe('systemInfo'),Meteor.subscribe('testingOn'),Meteor.subscribe('invoicesWithCompanyDetails',startingDate,endingDate)];
\t }
});
Pages = new Meteor.Pagination(PurchaseHistory, {
\t itemTemplate: "invoice",
\t availableSettings: {filters: true},
\t filters: {},
\t route: "/store/invoices/:_username/:startingDate/:endingDate/",
\t router: "iron-router",
\t routerTemplate: "invoices",
\t routerLayout: "main",
\t sort: {
\t \t transactionDate: 1
\t },
\t perPage: 1,
\t templateName: "invoices",
\t homeRoute:"home"
});
看看集合轉換https://docs.meteor.com/api/collections.html也,你可能更喜歡denormalizing ... – Salketer
我看了看轉換;整潔,但你如何將它應用到alethes分頁集合?反規範化肯定會起作用,但是我正在構建的應用程序已經需要大量空間,我正在儘可能地提高效率。 –