Meteor如何从Meteor包中导出Meteor.publish和Meteor.method代码 [英] Meteor How to export Meteor.publish and Meteor.method code from within a Meteor package

查看:91
本文介绍了Meteor如何从Meteor包中导出Meteor.publish和Meteor.method代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个package.js文件

Here is a package.js file

Package.describe({
  summary: 'Client Collection Paging Class designed for use with Meteor'
});

Package.on_use(function (api) {
    api.use( 'underscore', [ 'client', 'server' ] ) ;
    api.use( 'ejson', [ 'client', 'server' ] ) ;
    api.add_files( 'lib/pageMan.js',  'client' ) ;
    //api.add_files( 'lib/pageMan_publish.js', 'server' ) ;
    //api.add_files( 'lib/pageMan_method.js', [ 'client', 'server' ] ) ;

    if ( typeof api.export !== 'undefined' ) {
        api.use( 'webapp', 'server' ) ;
        Npm.depends( { connect: '2.7.10' } ) ;
        api.export( 'Pager', 'client' ) ;
      //api.export( 'methods', [ 'client', 'server' ] ) ;   
      //api.export('publish', 'server' ) ;
        api.export( 'pagingUpdate', 'client' ) ;
        api.export( 'pagingSubscribe', 'client' ) ;
        api.export( 'pagingFirst', 'client' ) ;
        api.export( 'pagingNext', 'client' ) ;
        api.export( 'pagingPrev', 'client' ) ;
        api.export( 'pagingLast', 'client' ) ;

    } ;
      });

我在/lib/pageMan_method.js中有一个Meteor.method,在/lib/pageMan_publish.js中有一个Meteor.publish 如果将这两个文件中的代码放在示例应用程序中的相应文件中,则该应用程序可以正常运行.我试图将它们添加到我的程序包中,但是当我取消注释packages.js文件中的4个引用时,服务器控制台报告

I have a single Meteor.methods in /lib/pageMan_method.js and a single Meteor.publish in /lib/pageMan_publish.js If the code from these two files is placed in appropriate files in an example app the app works fine. I am trying to add them to my package but when I un-comment the 4 references in the packages.js file, the Server console reports

Object #<Object> has no method 'publish'  or  Object #<Object> has no method 'method'

我确实尝试过api.use('meteor', ['client','server'],但也没有乐趣.

I did try an api.use('meteor', ['client','server'] but no joy either.

如果...可以请有人启发我

Could someone please enlighten me if...

  • 是否可以从包中导出出版物和方法?
  • 我可以正确执行吗?

推荐答案

确保使用livedata软件包.

Make sure you use the livedata packages.

api.use( 'livedata', [ 'server' ] ) ;

通常情况下,程序包可以访问非常准系统的流星. (绝对没有包).

Typically the packages have access to a very barebones version of meteor. (With absolutely no packages).

这篇关于Meteor如何从Meteor包中导出Meteor.publish和Meteor.method代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆