meteor - 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
解决方案
推荐阅读
- java - Spring JPA HQL 枚举“in 子句”查询
- javascript - 等待所有 dom 更新完成
- python-3.x - 使用openpyxl检查它是否是工作簿的第一张最简单的方法是什么
- reactjs - React antd 4 Form in Modal resetFields 显示错误数据
- php - 带有 laravel 的 Paypal PHP SDK。在生产模式下加载配置端点时出现问题
- grafana - 存储聚合没有像我期望的那样组合
- arrays - 作为参数传递给函数的数组长度
- javascript - 如何在 JS 中使用 regExp 查找 $@º[]
- javascript - 由于花括号的变化而显示“语法错误”
- flutter - 搜索一个小部件,它在普通屏幕上构建一个列表