Meteor 中 Methods 的简单用法

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-21 15:41   1757   0
1.在服务器中定义methods:

Meteor.methods({
    getApkMsg:function(_id){

        console.log("Meteor.methods _id   "+_id);

        return FileRecords.findOne({_id:_id});//可以直接返回string
    }
});


2.在client的调用 或者 在android程序中调用

var _id="ddsfsdfds";
Meteor.call('getApkMsg',_id,function(error,msg){
    if(error){
        console.log("getApkMsg "+ " error:"+error);
        return;
    }
    console.log("getApkMsg "+ " msg:"+EJSON.stringify(msg));//msg是一个Object类型 用EJSON解析
});

在andoird中调用:
   
      mMeteor = new Meteor(mUrl);
        mMeteor.setCallback(this);
 mMeteor.call("getApkMsg", new String[] {_id}, new ResultListener() {

            @Override
            public void onError(String arg0, String arg1, String arg2) {

                Log.d(TAG, "getApkMsg  arg0=" + arg0 + " |arg1=" + arg1
                        + "  |arg2=" + arg2);
            }

            @Override
            public void onSuccess(String arg0) {
                Log.d(TAG, "getApkMsg  arg0=" + arg0);

            }

  });

  
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP