- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
奇怪的问题。我正在运行 Node/Express/Mongoose/Leaflet。我从我的数据库中提取了一组位置,一旦启动回调,我就会遍历这些位置以找到一堆处理每个位置的字符串段落。然后,我尝试将段落数组附加到每个位置对象,然后将位置数组附加到 GeoJSON FeatureCollection。
Location.find({}, { _id: 0 }, function (err, locations) {
if (err) {
console.log('DB Error loading all locations');
res.redirect('/');
} else {
var num = 0;
console.log("Beginning finding all passages");
locations.forEach(function (location) {
num++;
console.log("Looking up a location");
Passage.find({"placekey": location.properties.placekey}, function (err, passages) {
if (err) {
console.log('DB Error finding passage for: ' + location.properties.placekey);
} else {
console.log("Passage was found!");
location.properties.passages = passages[0]; //take first passage
num--;
}
if (num === 0) {
console.log("All passages were found!");
var featureCollection = {
"type": "FeatureCollection",
"features": locations
};
console.log(featureCollection);
console.log(featureCollection.features[0].properties);
console.log(featureCollection.features[0].properties.passages);
res.json(featureCollection);
console.log("JSON sent over!");
}
});
});
记录 featureCollection 得到我的 featureCollection 而没有任何段落:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"num_books": 62,
"Age": "Built 1078",
"ID": "",
"num_mentions": 325,
"Place": "The Tower",
"placekey": "TheTower",
"GeocodeNotes": "",
"Notes": "Built on the site of Roman fortifications, the central part of the Tower, known as the White Tower, was built in 1078 by William the Conqueror. Subsequent rings of fortification were added later. It was used as a royal residence as well as a prison and place of execution until Elizabethan times. England's child king, Edward V, and his brother were murdered in the Tower in 1483 supposedly by their uncle, Richard III.",
"Class": "n/a",
"Type": "Landmark"
},
"geometry": {
"type": "Point",
"coordinates": [
-0.076111,
51.508056
]
}
},
// more objects
没有段落属性。
但是,当我使用 console.log(featureCollection.features[0].properties.passages) 时,我得到了第一段:
{
"_id": "51deebdbb2b5de1b8b6d7da1",
"index": 27100,
"bookid": 1,
"author": "Ainsworth, William",
"place": "The Tower",
"placekey": "TheTower",
"query_ok": true,
"year": 1839,
"corpus": "Chadwyck",
"fn": "/Volumes/LilaData1/Plain2/Chadwyck/lilaBookId_00149.txt",
"context_a": "The course of the carpenter's meditations was here...
//more features
}
此外,使用(如果 featureCollection.features[0].properties 中的“passages”)给了我真实的信息。事实上,我可以设置从服务器向其发送 JSON 响应的条件,并且我的没有段落的 featureCollection 将被发送...
抱歉这篇冗长的帖子,但我真的为此疯狂。有任何想法吗?
谢谢! :)
最佳答案
问题是 Document 上定义的检查干扰了 console.log 操作。此检查不考虑添加到文档实例的属性(如 documentinst.prop=1)。
要解决您的问题,请尝试在返回文档上使用 toJSON,然后将属性附加到返回对象
在你的情况下,
var _locations = [];
locations.forEach(function(_location){ // actual mongoose document
var location;
location = _location.toJSON(); // do toJSON on the _location mongoose document
_locations.push(location); //push this object into the new array _locations
....logic for passages...
//imp - add properties to the location object return from toJSON
if (num === 0) {
...
var featureCollection = {
"type": "FeatureCollection",
"features": _locations // use the new _locations array
};
...
}
});
关于Javascript 对象 - 整体对象缺少的功能,但存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18408906/
我正在阅读Head First Design Patterns一书,在第382页上说: Composite Patterns is used when you have collection of o
我将我的电脑用作 wifi 热点,并将其他设备连接到它。然后使用wireshark,我可以看到特定设备上发送/接收的数据包,但是我怎样才能看到设备正在查看的完整网页而不是单独的数据包? 最佳答案 尝试
在 URL 中打开我的 Jenkins 时,我似乎无法登录它会抛出消息“用户缺少整体/读取权限”。我试过answer来自类似的问题,但禁用安全性不起作用。 Jenkins 继续抛出错误。有人建议我一起
我已经使用工具分配测试了我的应用程序并得到了这张图片: 如图所示,我的应用程序正常工作,但它通常以总字节数计值吗?我担心“#Allocations (Net/Overall)”,因为它的颜色是红色。这
我遵循教程 Deployment on Tomcat without modification of monitored webapps (beta) .监控站点正在运行,我可以看到统计页面。问题是
所以我有一个 div,其中整个东西都是一个 anchor 标记,我试图控制颜色在悬停时的显示方式并获得不同的结果。希望我能用 CSS 做到这一点。发生的事情是悬停,一个文本发生变化,但另一个没有。但是
我创建了一个程序,您可以在其中输入行驶的英里数和每 jar 油使用的加仑数,该程序会显示每 jar 油的 mpg。我使用的是 Visual Studio 2010。当我输入标记值 -1 时,系统会给出
我有一个由 N 个节点组成的 zookeeper 集群(彼此了解)。如果我在 zk 客户端连接字符串中只传递 M < N 个节点地址怎么办?集群的行为是什么? 在更具体的情况下,如果我只从集群中传递
我一直在试图弄清楚当使用诸如 pushViewController:animated、presentModalViewController:animated 和 UITabBarViewControl
我已经在 VIM 中安装了 minikube,并且我拥有具有所有权限的服务帐户 token 。是否有来自 kubernetes 的 API 来获取资源使用情况(总体)。 最佳答案 要获取 CPU 和内
如何通过 HTTP 客户端(例如 CURL、Insomnia、Postman 等)快速使用使用 JWT token 的 JHipster 生成的应用程序? 最佳答案 嗯,我研究了一段时间,发现你必须遵
我是一名优秀的程序员,十分优秀!