参数更改后,动态订阅无法在客户端上接收数据

如何解决参数更改后,动态订阅无法在客户端上接收数据

当前尝试更改现有页面的订阅,以便用户可以在客户端上设置的一系列过滤器影响结果

客户端上的代码类似于此模板

创建时

Template.primeentry.onCreated(function () {
    let self = this
    this.selectedCompany = Meteor.user().profile.im3core.selectedusergroup;
    this.subscribe('im3coredocumenttype.all',{ "__im3coreOwnership.groups": this.selectedCompany });
    this.subscribe('im3coredocument.allDocsPayments',{ "__im3coreOwnership.groups": this.selectedCompany });
    this.subscribe('im3corepaymentmode.allFilteredToModes',{ "__im3coreOwnership.groups": this.selectedCompany });
    this.subscribe('im3corepartnertype.all',{ "__im3coreOwnership.groups": this.selectedCompany });
    this.subscribe('im3corepricelist.all',{ "__im3coreOwnership.groups": this.selectedCompany });
    this.subscribe('im3corepartner.all',{ "__im3coreOwnership.groups": this.selectedCompany });
    this.subscribe('im3corewarehouse.all',{ "__im3coreOwnership.groups": this.selectedCompany });
    this.subscribe('im3corecontact.all',{ "__im3coreOwnership.groups": this.selectedCompany });
    this.subscribe('im3coreaccount.all',{ "__im3coreOwnership.groups": this.selectedCompany });
    this.subscribe('im3corevat.all',{ "__im3coreOwnership.groups": this.selectedCompany });
    this.subscribe('im3corefiscalretention.all',{ "__im3coreOwnership.groups": this.selectedCompany });
    this.subscribe('im3corecompany.mine');

    this.subscribe('im3coremoneysearch.all',{ "__im3coreOwnership.groups": this.selectedCompany })
    this.subscribe('im3coremoneytransactionManual.all',{ "__im3coreOwnership.groups": this.selectedCompany });
    this.subscribe('im3coreprimeEntryManualModes',{ "__im3coreOwnership.groups": this.selectedCompany })
    this.subscribe('im3.core.primeEntryPreviousTotals',{ "__im3coreOwnership.groups": this.selectedCompany })

    this.showTotalColumns = new ReactiveVar(false);
    this.totalBalance = new ReactiveVar(0);
    this.totalAmount = new ReactiveVar(0);
    this.supplier_clientSelector = new ReactiveVar("-1")
    this.supplier_clientId = new ReactiveVar("-1")

    let newDateYear = new Date().getFullYear() + 1
    this.toDateIso = new ReactiveVar(new Date(newDateYear,1))
    this.fromDateIso = new ReactiveVar(new Date(newDateYear - 1,1))
    this.userId = Meteor.userId()
    this.im3money = im3core.im3money
    this.paymentModes = im3core.im3money.fatturaElettronicaenaledPaymentModes
    this.addrows = new ReactiveVar([{ destinations: 1 }])
    this.accountsList = new ReactiveVar([])
    this.accountTotals = []
    this.accountFromId = new ReactiveVar("-1")
    this.Refresh = new ReactiveVar(true)
    this.transactionsList = new ReactiveVar()
    this.moveToLine = -1
    this.PrefilterLine = []
    this.previousData = new ReactiveVar({})
    this.limit = new ReactiveVar(20)
    this.skip = new ReactiveVar(0)
    this.alreadyPassed = false;
    this.autorun(() => {
        this.subscribe('im3coremoneytransactions.allForPrimeEntry',{
            '__im3coreOwnership.groups': this.selectedCompany,"date": {
                $gte: new Date(this.fromDateIso.get()),$lte: new Date(this.toDateIso.get())
            }
        },{
            sort: { date: -1 },limit: this.limit.get(),skip: this.skip.get()
        })
    })
    Meteor.call('UpdatePreviousYear',this.selectedCompany,new Date().getFullYear(),this.limit.get(),function (err,result) {
        console.log("runsetup ==>",err || result);
        if (err) {

        } else {
            self.previousData.set(result)
            let valuesList = GetAccountsRender(self)
            console.log("valuesList",valuesList)
            SetupAccountTotalsWithPreviousYearsRender(valuesList,self);
            self.Refresh.set(false)
        }
    });

    //im3primeentry.accountsList=this.accountsList
})

onRendered

Template.primeentry.onRendered(function () {
    let instance = this
    let dateFrom = instance.fromDateIso.get()
    let yyyy = String(new Date(dateFrom).getFullYear())
    let mm = new Date(dateFrom).getMonth() + 1 > 9 ? String(new Date(dateFrom).getMonth() + 1) : "0" + String(new Date(dateFrom).getMonth() + 1)
    let dd = new Date(dateFrom).getDate() > 9 ? String(new Date(dateFrom).getDate()) : "0" + String(new Date(dateFrom).getDate())
    $("#fromDate").val(yyyy + "-" + mm + "-" + dd)
    let dateTo = instance.toDateIso.get()
    let year = String(new Date(dateTo).getFullYear())
    let month = new Date(dateTo).getMonth() + 1 > 9 ? String(new Date(dateTo).getMonth() + 1) : "0" + String(new Date(dateTo).getMonth() + 1)
    let day = new Date(dateTo).getDate() > 9 ? String(new Date(dateTo).getDate()) : "0" + String(new Date(dateTo).getDate())
    $("#toDate").val(year + "-" + month + "-" + day)

    instance.autorun(() => {
        let isRefreshing = instance.Refresh.get()

        if (this.subscriptionsReady() && isRefreshing == false && instance.alreadyPassed == false) {
            let valueList = Template.instance().accountsList.get()
            console.log("valuelist onrender",valueList)
            /* let valuesList = GetAccounts()
            console.log("valuesList",valuesList)
            SetupAccountTotalsWithPreviousYears(valuesList); */
            let im3money = instance.im3money
            let company = Template.instance().selectedCompany
            Template.instance().registerAccount = im3core.accountCollection.findOne({ "__im3coreOwnership.groups": company,isRegister: true })
            let transactionFilterDateFrom = new Date(Template.instance().fromDateIso.get())
            let transactionFilterDateTo = new Date(Template.instance().toDateIso.get())

            let result = [];
            if (typeof company != "undefined") {
                let transactionsList = GetTransactions(im3money,instance)
                transactionsList.forEach(transaction => {
                
                //code i'm omitting because it's not relevant to the problem

                })
            }
            
            

            instance.alreadypassed = true
        }
    })
})

GetTransactions函数

function GetTransactions(im3money,instance) {
    return im3money.moneytransactionsCollection.find({
         '__im3coreOwnership.groups': instance.selectedCompany,"date": {
                $gte: new Date(instance.fromDateIso.get()),$lte: new Date(instance.toDateIso.get())
            }
        },limit: instance.limit.get(),skip: instance.skip.get()
    }).fetch();
}

现在,该页面具有4个控件(2个按钮和2个日期输入)以及用于更新日期和跳过ReactiveVars的相应事件

事件

    "change #fromDate": function (event,instance) {
        let x = $(event.currentTarget).val()
        let dateSplit = x.split('-')
        let dateValue = new Date(dateSplit[0],+dateSplit[1] - 1,dateSplit[2])
        instance.fromDateIso.set(dateValue)

    },"change #toDate": function (event,dateSplit[2])
        instance.toDateIso.set(dateValue)
    },"click .pageBack": function (event,instance) {
        let current = +instance.skip.get()
        current += 20
        instance.skip.set(current)
    },"click .pageNext": function (event,instance) {
        let current = +instance.skip.get()
        if (current >= 20) {
            current -= 20
            instance.skip.set(current)
        }
    }

没有什么花哨的东西让我期望它会造成问题。

但是...

首次使用默认的ReactiveVars设置加载页面时,一切正常。客户端按预期从“ im3coremoneytransactions.allForPrimeEntry”订阅中接收数据。

此后,如果我使用输入控件更改日期值,则一切仍然有效,客户端将获得所选日期范围内包含的新值

一旦我尝试更改跳过值,客户端上的GetTransaction就会返回一个空数组。

我知道服务器的发布正确接收到了更改的参数,因为我在其中发布了一行内容来记录将要发送到客户端的内容,并且一切都在此显示,例如服务器日志显示了一个数组正确跳过记录更新数量的交易)

我很确定我在这里忽略了一些非常基本的内容,但是日期切换有效且只有跳过更改这一事实并没有使我陷入循环(我希望这两种类型的过滤器都能起作用或返回为空而不是采取相反的方式),而我无法查明错误。

解决方法

您需要将反应性数据源移至如下所示的自动运行中。

...
this.autorun(() => {
       this.selectedCompany = Meteor.user().profile.im3core.selectedusergroup;
        this.subscribe('im3coremoneytransactions.allForPrimeEntry',{
            '__im3coreOwnership.groups': this.selectedCompany,"date": {
                $gte: new Date(this.fromDateIso.get()),$lte: new Date(this.toDateIso.get())
            }
        },{
            sort: { date: -1 },limit: this.limit.get(),skip: this.skip.get()
        })
    })
...
,

好吧,忘了跟进,说我发现了问题,而且我担心这真是愚蠢。

我正在对从发布中获得的结果进行跳过,该结果与我在发布本身中用作限制的值完全相同。意味着最终值显然显示为空

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-