我正在尝试从中获取我的事件对象,route.params但我不知道如何让打字稿识别此道具。
这是导航到我的详细信息页面的函数,将事件传递给参数:
const navigateToDetail = (incident: IncidentProps): void => {
navigation.navigate('Detail', { incident });
};
Run Code Online (Sandbox Code Playgroud)
这是我尝试从 route.params 获取此对象的详细信息页面代码的一部分:
type IncidentRouteParams = {
incident: IncidentProps;
}
const Detail: React.FC = () => {
const navigation = useNavigation();
const route = useRoute();
const incident = route.params.incident;
Run Code Online (Sandbox Code Playgroud)
我想我需要以某种方式将这个IncidentRouteParams类型传递给const route = useRoute()
提前致谢。
这是带有错误的图像:
编辑:
我确实喜欢这个,并且它有效,但我不知道它是否是正确的方法:
const route = useRoute<RouteProp<Record<string, IncidentRouteParams>, string>>();
const incident = route.params.incident;
Run Code Online (Sandbox Code Playgroud)
我有以下示例组件
export default class Header extends Component{
render(){
let activeStyle = {"backgroundColor": "green"};
let inActiveStyle = {"backgroundColor": "red"};
return(
<div className="profile-header" style={(this.props.active)?
activeStyle:inActiveStyle}>
<input type="checkbox" checked={this.props.active} readOnly/>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
使用酶和柴我想断言,为
this.props.active = true
Run Code Online (Sandbox Code Playgroud)
backgroundColor为绿色,并选中复选框.
这是我的测试用例
describe('<Header />', () => {
it('valid component', () => {
const wrapper = shallow(<ProfileHeader
active= {true}
/>);
????
});
Run Code Online (Sandbox Code Playgroud)
但我怎么能断言这两种情况呢?
在我的 HTML 文档中,有一个图像
<img src="https://www.gravatar.com/avatar/1d9c87a4d5cbcae4c76e867cb6861fa0?s=48&d=identicon&r=PG&f=1"/>
Run Code Online (Sandbox Code Playgroud)
当在浏览器(例如 Chrome)中打开该文档时,我们可以根据 HTTP 响应标头找到Content-Type该图像位于Chrome 开发者工具 -> 网络选项卡中。"image/png"
Content-Type图像加载后如何使用JavaScript。
更具体地说,我需要的是如下所示的函数。
/**
* @param {HTMLImageElement} img
* @return {String} the content type, e.g. "image/png", "image/svg+xml"
*/
getImgContentType(img) {
// TODO
}
Run Code Online (Sandbox Code Playgroud) 我有一个按钮,改变了它的文本enable和disable上点击。
我怎样才能改变按钮颜色,
例如更改为绿色亮起enable和红色亮起disable
<button (click)="enableDisableRule()">{{status}}</button>
Run Code Online (Sandbox Code Playgroud)
成分
toggle = true;
status = 'Enable';
enableDisableRule(job) {
this.toggle = !this.toggle;
this.status = this.toggle ? 'Enable' : 'Disable';
}
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏。谢谢
我需要将反应传单地图定位到用户的当前位置并获取该地图的边界。我尝试应用以下代码,但遇到了错误:
类型错误:无法读取未定义的属性“定位”(匿名函数)
请帮我!
import React, { useState, useEffect, useRef } from 'react';
import restaurantsInfo from "./RestaurantsList.json";
import "./App.css";
import { MapContainer, Marker, Popup, TileLayer, useMapEvents } from "react-leaflet";
import { Icon, latLng } from "leaflet";
import Restaurants from "./Restaurants.js";
import LocationMarker from "./LocationMarker.js";
import L from 'leaflet';
const myLocation = [49.1951, 16.6068];
const defaultZoom = 13;
export default function App() {
const mapRef = useRef();
useEffect(() => {
const { current = {} } = mapRef;
const { leafletElement: map …Run Code Online (Sandbox Code Playgroud) 任何人都可以帮助我如何div在不删除内容的情况下删除标签JavaScript?
这是我需要删除所有div标签的html:
<div id="id1" class="someclass">
<p>some text
<label> Test content </label>
</p>
<div id="id2" style="overfolw:scroll">
<span>some text</span>
<div id="level3">
<label> Test content </label>
<a href="https://twitter.com/realDonaldTrump/status/882186896285282304" target=_blank rel=noopener>creepiness</a>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
预期输出如下所示.
<p>some text
<label> Test content </label>
</p>
<span>some text</span>
<label> Test content </label>
<a href=https://twitter.com/realDonaldTrump/status/882186896285282304 target=_blank rel=noopener>creepiness</a>
Run Code Online (Sandbox Code Playgroud) 我试图将MatSnackbar模块定位在页面顶部.
我试过用它config来添加customclass.这是我的代码:
component.ts
let config = new MatSnackBarConfig();
config.duration = 50000;
config.panelClass = ['red-snackbar']
this.snackBar.open("Please fill all the details before proceeding.", null, config);
Run Code Online (Sandbox Code Playgroud)
的CSS
.red-snackbar{
position: absolute !important;
top: 54px;
}
Run Code Online (Sandbox Code Playgroud)
但它没有用.是否可以重新定位MatSnackbar?
我尝试将 GeoJson 文件导入到 angular 应用程序 6 中的传单中。
使用此解决方案,我的 geojson 是在传单图中绘制的,但出现此错误,我无法构建我的应用程序。有人知道一种解决方案吗?
错误 TS2345 类型参数 '{"type": string;"features":({"type": string; "geometry": { "type: string : "coordinates": num...' 不是类型的可分配参数GeoJson 对象
模型.ts
export const Pdl = [ 'my geojson' ];
Run Code Online (Sandbox Code Playgroud)
组件.ts
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
import * as L from 'leaflet';
import {Pdl} from "../models/pdl.model";
@Component({
selector: 'app-geo',
templateUrl: './geo.component.html',
styleUrls: ['./geo.component.scss']
})
export class GeoComponent implements OnInit {
ngOnInit() {
var mapboxAccessToken = "...";
const myfrugalmap = L.map('frugalmap').setView([47.482019, -1], 7);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=' + …Run Code Online (Sandbox Code Playgroud) 我正在使用反应传单与传单地图进行交互。现在我想使用一个名为 Leaflet-area-select 的传单插件来选择地图上的一个区域,并获取所选矩形的当前长纬度。但是,它是一个传单插件,不能在反应传单上使用。我怎样才能使用这个插件?或者你知道任何可以从传单地图中选择区域的图书馆吗?非常感谢!
选择区号(leaflet-area-select):
let map = new L.Map('map', {
selectArea: true // will enable it by default
});
// or
map.selectArea.enable();
map.on('areaselected', (e) => {
console.log(e.bounds.toBBoxString()); // lon, lat, lon, lat
});
// You can restrict selection area like this:
const bounds = map.getBounds().pad(-0.25); // save current map bounds as restriction area
// check restricted area on start and move
map.selectArea.setValidate((layerPoint) => {
return bounds.contains(
this._map.layerPointToLatLng(layerPoint)
);
});
// now switch it off
map.selectArea.setValidate();
Run Code Online (Sandbox Code Playgroud)
我的代码:
export default function Home(){ …Run Code Online (Sandbox Code Playgroud) 我想根据值从函数中选中和取消选中复选框,如果假设复选框值为 120,如何选中该复选框
<input type="checkbox" [checked] = "isEnabled" value={{rowData.FILE_LOAD_ID}} id={{rowData.FILE_LOAD_ID}}>
Run Code Online (Sandbox Code Playgroud) javascript ×5
angular ×4
leaflet ×3
reactjs ×3
typescript ×3
html ×2
checkbox ×1
dom ×1
enzyme ×1
geojson ×1
image ×1
jquery ×1
mime-types ×1
ng-class ×1
ngx-leaflet ×1
react-native ×1
testing ×1