我试图触发调整大小而不实际调整屏幕大小,因为它修复了我的滑块。
window.dispatchEvent(new Event('resize'));
Run Code Online (Sandbox Code Playgroud)
上面的代码不起作用,有没有人有其他方法在反应中触发调整大小?
必须使用 jQuery:
jQuery(window).resize();
Run Code Online (Sandbox Code Playgroud) 在过去的几个小时里,我一直用头撞桌子。
我试图让 Mapbox 放大所有标记的边界区域的负载。
但是,这是我在下面的代码中遇到的错误。
此错误出现在下面的控制台日志图像之后,因此 lat lng 坐标肯定存在。
未捕获的错误:无效的 LngLat 对象:(NaN,NaN)
const onLoad = () => {
let points = [];
props.cats.forEach(cat => (
points.push([ cat.lat, cat.lng ])
));
points.length > 0 && ref.current.getMap().fitBounds(points, {
padding: { top: 50, bottom: 50, left: 50, right: 50 },
easing(t) {
return t * (2 - t);
},
});
};
Run Code Online (Sandbox Code Playgroud)
如何调整下面的代码,以便在调整浏览器/屏幕大小时调整地图大小?(第一次在没有高级开发人员帮助的情况下使用 Mapbox)。
根据我自己的研究,有一些代码库可以在地图容器上添加事件侦听器并侦听该事件侦听器以调整大小,然后我可以以编程方式调用 map.resize() 。但是,我想知道最佳实践是什么,因为这种方式感觉有点老套。
代码
const applyToArray = (func, array) => func.apply(Math, array)
const getBoundsForPoints = (points) => {
console.log('Points:', points)
// Calculate corner values of bounds
const pointsLong = points.map(point => point.geometry.coordinates[0])
const pointsLat = points.map(point => point.geometry.coordinates[1])
const cornersLongLat = [
[applyToArray(Math.min, pointsLong), applyToArray(Math.min, pointsLat)],
[applyToArray(Math.max, pointsLong), applyToArray(Math.max, pointsLat)]
]
// Use WebMercatorViewport to get center longitude/latitude and zoom
const viewport = new WebMercatorViewport({ width: 600, height: 600 })
// @ts-ignore
.fitBounds(cornersLongLat, { padding: {top:20, bottom: 90, …Run Code Online (Sandbox Code Playgroud) 仅iOS / iPhone X / iPhone 7等
甚至jQuery模式库也不起作用!https://jquerymodal.com/-在iPhone上打开模态,您将能够滚动主体。
我发现很难找到一种在每次打开模态时都不会使页面跳到顶部而停止主体滚动的解决方案(这与页面滚动一样糟糕)
看来这是一个很大的问题,许多人都在经历。如您所见:
我没有运气就上网了,有人可以解决吗?
在 setState 上我收到此 TS 错误:
“类型‘AxiosResponse’缺少类型‘countries[]’中的以下属性:length、pop、push、concat 和 26 more.ts(2740)”
谁能建议出什么问题/在哪里使用 :countries[] ?
export interface IProfileEditorState {
countries: countries[];
}
interface countries {
countryID: string;
countryName: string;
label: astring;
value: string;
isDirector: number;
}
// Temp
public getCountrys() {
axios
.get('https://func-myportal-dev.azurewebsites.net/api/GetCountries?code=j0xGK8L6iRXpZqR3DgaDRoI/H/qjGZSGdBPIY9rZU84uH4SUa80noQ==')
.then(res => {
this.setState({countries: res});
})
// Error catching
.catch(error => this.setState({ error, isLoading: false }));
}
Run Code Online (Sandbox Code Playgroud) 这是我第一次使用反应。我从 jQuery 到 React 这感觉就像一个很大的飞跃。如果有人能帮我重构它以按照 React 的方式工作,我将永远欠你的债!:)
我正在尝试解析 RSS 提要,我想在其中获取最新的帖子标题和链接以呈现到组件中。
https://www.npmjs.com/package/rss-parser - 使用它来获取解析器。
在浏览器中查看我的应用程序时,异步函数将 rss 提要吐出到控制台,我想这是一个好的开始!
// src/App/index.tsx
import * as React from 'react';
import * as Parser from 'rss-parser';
// Types
import { string } from 'prop-types';
let parser = new Parser();
// blueprint for the properties
interface Props {
name: string;
}
// Component state
interface State {
//feed: any[];
}
(async () => {
let feed = await parser.parseURL('https://www.reddit.com/.rss');
console.log(feed.title);
feed.items.forEach((item: { title: string; link: string; }) …Run Code Online (Sandbox Code Playgroud) 我正在使用使用JSON JSON端点的react创建一个spfx小部件。然后,它吐出最新的帖子。
将{url}变量添加到时<a href=""></a>-网址是一个随机的本地主机,而不是完整的网址
<a href="{url}">{url}</a>
Run Code Online (Sandbox Code Playgroud)
在{url}该标记内是实际的完整链接https://etc..但一个内部href=""匝到像本地主机链接:
https://开头本地主机:4321 /温度/%7B%60url%60%7D
任何想法为什么?
这是我通过 API 请求存储在 this.state.profile 中的对象数据。
我需要知道的是将键中的值渲染到网络浏览器。我正在尝试使用下面的代码,但它不起作用。另外,如何渲染该对象旁边的对象?这一切都太令人困惑了:(
{
"localizedLastName": "King",
"lastName": {
"localized": {
"en_US": "King"
},
"preferredLocale": {
"country": "US",
"language": "en"
}
},
"firstName": {
"localized": {
"en_US": "Benn"
},
"preferredLocale": {
"country": "US",
"language": "en"
}
},
"profilePicture": {
"displayImage": "urn:li:digitalmediaAsset:C5603AQGjLGZPOyRBBA"
},
"id": "fm0B3D6y3I",
"localizedFirstName": "Benn"
}
Run Code Online (Sandbox Code Playgroud)
我如何尝试渲染它:
const { profile } = this.state;
const profileList = Object.keys(profile).map((key,value)=>{
return (
<div>{key}{value.toString()}</div>
);
})
{ profileList }
Run Code Online (Sandbox Code Playgroud) reactjs ×5
javascript ×4
axios ×2
mapbox ×2
css ×1
html ×1
mapbox-gl ×1
mapbox-gl-js ×1
rss ×1
typescript ×1