首页 > 解决方案 > Meteor isServer 没有立即调用

问题描述

我目前在调用 SQL 数据上的服务器端代码时遇到问题,客户端总是首先被调用,我必须等待大约 5 分钟或更长时间才能调用服务器端。在少数情况下,不会调用服务器端。这是粗略的代码和文件结构。有没有办法在不等待很长时间的情况下调用服务器端?

statistics.html,调用服务器的页面

<template name="statistics">
    <div class="content">

        <h2>HTML Forms</h2>

        <div class="row">
            <div class = "col-lg-2">

                <button type="button" class="btn btn-primary getdata" >Get stats</button>
            </div>
        </div>

    </div>
</template>

statistics.js,调用 getData 函数

Template.statistics.events({
    'click .getdata'(event, instance){
        alert("get data")
        Meteor.call('getSqlData', function(err, response) {
            if(err){
                console.log("err is "+err)
            }
            console.log(response);
        });
    }
});

sqlData.js,函数 getSqlData

Meteor.methods({
getSqlData: function(){
        console.log("at sqldata");
        if(Meteor.isClient){
            console.log("shouldn't be here")
        }
        if(Meteor.isServer){
            console.log("server side")
            //go to a directory and get the file names to be read
            //get the data in the files and insert into mongoDB
        }
});

我的文件结构是这样放置的
Project
├── imports
│ ├── ui
│ │ ├── pages
│ │ │ ├── statistics.js
│ │ │ ├── statistics.html
├── lib
│ ├──集合
│ │ ├── sqlData.js

标签: meteor

解决方案


推荐阅读