我的问题是,react-leaflet<MapContainer>并不以我动态设置的位置为中心。基本逻辑是,我有一个表单,在其中输入街道和门牌号,然后调用 Nominatim 并获取一些 JSON 格式数据,从中提取建筑物的纬度和经度。这些经纬度我传递给我的<MapContainer>,但它无论如何都没有回应。使用react-leaflet v2它工作得很好,但是在我更新到v3之后它就停止了。
每当我设置默认位置值时,MapContainer 都会以该位置为中心。但是,当我通过 Nominatim 调用动态传递另一个值时,它不起作用。
我在这里呼吁提名:
const getSearchData = async () => {
const exampleReq = `https://nominatim.openstreetmap.org/search/${query}?format=json&building=*&addressdetails=1&limit=1&polygon_geojson=1`;
const response = await fetch(exampleReq);
const data = await response.json();
// console.log(data);
if (data === undefined || data.length === 0) {
// array empty or does not exist
console.log("data array is empty");
alert("Given address unrecognized! Try again please.")
setLatitude(DEFAULT_LATITUDE);
setLongitude(DEFAULT_LONGITUDE);
}else{
setLatitude(data[0].lat);
setLongitude(data[0].lon);
}
};
Run Code Online (Sandbox Code Playgroud)
这是我的表单的提交:
<form className={style.searchForm} onSubmit={e => {
e.preventDefault();
setQuery(street + …Run Code Online (Sandbox Code Playgroud) 我是Puppeteer的新手,我正在尝试使用Node.JS和Puppeteer从网站中提取元数据.我似乎无法正确使用语法.下面的代码使用两种不同的方法以及段落标记中的文本来完美地提取Title标记.如何提取名称为"description"的元数据的内容文本?
meta name ="description"content ="Stack Overflow是最大的,等等"
我会非常感谢任何建议!我似乎无法在任何地方找到任何这样的例子(5小时的搜索和代码黑客攻击).我的示例代码:
const puppeteer = require('puppeteer');
async function main() {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto('https://stackoverflow.com/', {waitUntil: 'networkidle2'});
const pageTitle1 = await page.evaluate(() => document.querySelector('title').textContent);
const pageTitle2 = await page.title();
const innerText = await page.evaluate(() => document.querySelector('p').innerText);
console.log(pageTitle1);
console.log(pageTitle2);
console.log(innerText);
};
main();
Run Code Online (Sandbox Code Playgroud) 我想为客户制定 2 个订阅计划。计划 A 他们将每月支付 5 加元。Plan B 他们将每月支付 10 美元。因为这是一个特殊的客户,所以我们必须设计一个新的计划,他们将用加元支付。如何在 Stripe 中进行设计?因为当我使用 API 时stripe.subscriptions.create,当他们想要在计划之间切换时,它会显示此问题
Error: The specified price uses `usd` which doesn't match the expected currency of `cad`. Use `cad` instead.
我有一组看起来像这样的对象
[{
name: 'some name'
catId: 2,
}, {
name: 'another name'
catId: 3,
}]
Run Code Online (Sandbox Code Playgroud)
如何使用类验证器进行验证,以便名称字段是必需的,并且每个对象的长度至少为 2 个字符?
谢谢
我是 React 和 Dagre-D3 的新手。我将此 Dagre-D3演示转换为 React 组件。我使用的代码如下所示。
import React from 'react'
import d3 from 'd3'
import dagreD3 from 'dagre-d3'
export default class EventFlow extends React.Component {
constructor () {
super();
}
componentDidMount() {
// Create the input graph
var g = new dagreD3.graphlib.Graph()
.setGraph({})
.setDefaultEdgeLabel(function() { return {}; });
// Here we"re setting nodeclass, which is used by our custom drawNodes function below.
g.setNode(0, { label: "TOP", class: "type-TOP" });
g.setNode(1, { label: "S", class: "type-S" }); …Run Code Online (Sandbox Code Playgroud) node.js ×2
reactjs ×2
arrays ×1
d3.js ×1
javascript ×1
leaflet ×1
meta-tags ×1
puppeteer ×1
validation ×1