- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用简单的 nvd3 discrete bar chart 显示集合中的数据.
当我尝试使用本地集合时,效果很好。现在我将相同的数据转移到数据库集合中,但我无法在 Meteor 的 .rendered 中获取数据。
Template.chartPopularWordsAll.onCreated(() => {
let template = Template.instance();
template.autorun(() => {
template.subscribe('dataViewed'); // DataViewed.find()
});
Template.chartPopularWordsAll.rendered = function() {
let data = DataViewed.find({}, {
limit: 5,
sort: {
timesViewed: -1
}
}).fetch();
console.log(data); // <-- this returns an empty array
}
问题:我如何访问 .rendered 中的数据?
在 Meteor 文档中搜索“.rendered”没有给出任何结果,我只能找到 .onRendered。 .rendered 是最新的还是已弃用?
提前致谢!
莫夫
最佳答案
我认为这里的问题是混合了订阅和获取的自动运行:
自动运行是在数据更改时运行的,因此不需要在自动运行中进行订阅,而是需要进行数据查找。
试试这个:
Template.chartPopularWordsAll.onCreated(() => {
let template = Template.instance();
template.subscribe('dataViewed'); // DataViewed.find()
});
Template.chartPopularWordsAll.rendered = function() {
template.autorun(() => {
let data = DataViewed.find({}, {
limit: 5,
sort: {
timesViewed: -1
}
}).fetch();
console.log(data); //
}
}
如果这不起作用,请尝试不获取对数据的调用,而是在需要数据时获取:Collection.find() 为您提供一个游标,它是 react 性的,但是一旦获取,您就会得到一个数组,这不是 react 性的。 Collection.find() 部分“应该”在自动运行中 react ,但我不能 100% 确定。
关于javascript - 如何在 Meteor 中的 nvd3 的 Template.rendered 中访问订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36580238/
[INFO] [INFO] --- dependency-check-maven:4.0.2:check (default) @ realtimePaymachine --- [INFO] Centr
我开始从 NVD XML 提要转向 JSON 提要(因为从 2019 年 10 月起不再支持 XML)。现在我很难理解这些标签及其使用目的。 例如: “配置”中的“运算符(operator)”标签有什
我的 IT 产品已定义 CPE,例如:cpe:/o:microsoft:windows_vista:6.0:sp1:~-~home_premium~-~x64~- 我正在使用 NVD 数据源来获取所有
我们正在使用 jQuery,我在国家漏洞数据库中发现了以下 jQuery 漏洞: http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2007-23
我正在尝试下载 NVD CVE。这是我的Python代码: import requests import re r = requests.get('https://nvd.nist.gov/vuln/
目前我正在使用 Angular-nvd3 图形来显示数据。但是,堆叠面积图 nvd3 图形类型正在切断数字和轴标签。模板图可查看here 。 y 轴数字和标签是主要关注点。下面是图形选项代码和问题的图
我们在项目中遇到以下错误,该URL何时返回? > Task :dependencyCheckAnalyze Verifying dependencies for project cckm-app
我在gitlab管道中使用gradle:5.6.2-jdk8 docker镜像。 gradle clean build 上面的命令因错误而失败: 无法下载元文件:https://nvd.nist.go
我是一名优秀的程序员,十分优秀!