我很难理解 'exhaustive-deps' lint 规则。
这是一个带有 lint 问题的简单 React 组件:
const MyCustomComponent = ({onChange}) => {
const [value, setValue] = useState('');
useEffect(() => {
onChange(value);
}, [value]);
return (
<input
value={value}
type='text'
onChange={(event) => setValue(event.target.value)}>
</input>
)
}
Run Code Online (Sandbox Code Playgroud)
它需要我添加onChange到useEffect依赖项数组。但在我的理解中onChange永远不会改变,所以它不应该存在。
通常我是这样管理的:
const MyCustomComponent = ({onChange}) => {
const [value, setValue] = useState('');
const handleChange = (event) => {
setValue(event.target.value);
onChange(event.target.value)
}
return (
<input
value={value}
type='text'
onChange={handleChange}>
</input> ?
)
} …Run Code Online (Sandbox Code Playgroud) 我用a Comparator来排序Student对象列表.
我想反转id属性的排序,但using reverse()方法将它应用于整个排序.
怎么让它发生在id?
到目前为止,这是我的代码:
public List<Student> getStudents(List<String> events) {
Comparator<Student> comparatorStudents = Comparator.comparing(Student::getCGPA).thenComparing(Student::getName)
.thenComparingInt(Student::getID).reverse();
List<Student> students = new ArrayList<Student>();
//Filling students
Collections.sort(students, comparatorStudents);
return students;
}
Run Code Online (Sandbox Code Playgroud) 在以下代码中:
setTimeout(() => console.log("hello"), 0);
Promise.resolve('Success!')
.then(console.log)
Run Code Online (Sandbox Code Playgroud)
在我的理解中应该发生什么:
print hello直接添加到回调队列,因为时间为 0print Success!添加到回调队列如果我没记错的话,回调队列是FIFO。
但是代码输出是:
Success!
hello
Run Code Online (Sandbox Code Playgroud)
解释是什么?
我正在使用Angular 5应用,正在将其托管在Apache2.4 http服务器上,并使用代理模块对其进行重定向 http://localhost:7777/test/
我的第一个问题是调用从浏览器服务时,它是使用http://localhost:7777/作为基本URL,从我的测试服务中删除斜杠尽快解决,/service1/upload给service1/upload。所以我从http://localhost:7777/service1/upload到了http://localhost:7777/test/service1/upload。
现在我image.png在Assets /文件夹中还有一个其他未解决的问题,它一直试图从中获取它,http://localhost:7777/assets/image.png而不是http://localhost:7777/test/assets/image.png
我测试了第二个URL,它按要求返回了我的图像。如何使Angular 5相对地找到我的资产路径?以我为例http://localhost:7777/test/assets/image.png
这是我访问HTML图像的方法:
..
<img src='assets/stop_pic.PNG' >
..
Run Code Online (Sandbox Code Playgroud)
我的基本href在我的index.html中:
<base href="">
Run Code Online (Sandbox Code Playgroud)
我的angular-cli.json conf:
...
apps": [
{
"root": "src",
"outDir": "../src/main/resources/static",
"assets": [
"assets"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
...
Run Code Online (Sandbox Code Playgroud) 我有一个使用 Maven 的 Java 项目。在我的项目中,我有一个名为的文件夹libs,其中包含我无法从 Internet/外部存储库加载的所有 JAR。
我的问题是如何指定 Maven 在打包、构建等过程中包含这些 JAR?
Maven 新手,抱歉,如果这是一个愚蠢的问题。
编辑:我有一个自动工具,可以pom.xml在我的 Git 上查找我的项目,以在不同的环境中构建和部署我的项目。因此,按照此处的建议将其添加到本地 Maven 存储库中将无济于事,因为它只能在我的 PC 上运行。如果我添加一个libs带有 JAR的文件夹,无论我在哪里,它都可以使用。
如果不清楚或者我弄错了,请在评论中问我。
在我的角度应用程序中,我有一个代表一个html表的组件.我遇到的问题是我无法降低细胞高度.好像我的css对显示器没有影响.
这里的headers&catNames var在我的component.ts中:
catNames : string[] = ["Toto", "Tata", "Titi", "Mama", "Momo"];
headers: string[] = ["Head1", "Head2", "Head3", "Head4", "Head5"];
Run Code Online (Sandbox Code Playgroud)
这是我的组件HTML:
<table>
<tr>
<th *ngFor="let header of headers">
{{header}}
</th>
</tr>
<tr>
<td *ngFor="let cat of catNames">
<p>{{cat}}</p>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
这是我的CSS:
table {
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
border-collapse: collapse;
text-align: center;
width: 100%;
font-size: 12pt;
}
th {
border: 1px solid #dddddd;
text-align: center;
padding: 0px;
color: white;
background-color: dodgerblue;
}
td { …Run Code Online (Sandbox Code Playgroud) 我正在开发一个角度应用程序,目前正在上传我正在使用的文件:
<label class="btn btn-default">
<input type="file" (change)="selectFile($event)">
</label>
<button class="btn btn-success" [disabled]="!selectedFiles"
(click)="upload()">Upload</button>
Run Code Online (Sandbox Code Playgroud)
使用我的.ts文件中的方法,它运行良好.
我想将此升级为物质角度组件凸起按钮,就像现在一样:
<button mat-raised-button>
<input type="file" (change)="selectFile($event)">
</button>
<button mat-button disabled [disabled]="!selectedFiles" (click)="upload()">Upload</button>
Run Code Online (Sandbox Code Playgroud)
禁用按钮运行良好,但输入文件部分不起作用,打印错误,不打开文件夹搜索窗口.有任何想法吗?
新的路由与角4/5,我在他们的网站上遵循角度教程.我有一个角度应用程序,我希望能够有两个单独的页面.现在主页是localhost:8870/dr3-interface,我想要一个新组件的新页面localhost:8870/dr3-interface/manage_cycles_instances
我的问题是,当我点击我的链接时,Manage cycles instances它会显示我的所有app.component组件,而不仅仅是我决定在我的组件上显示的组件/manage_cycles_instances.我试图隐藏它们*ngIf但没有结果.有任何想法吗?
app.component.html:
<div style="text-align:left">
<h1>{{ title }}</h1>
</div>
<nav>
<a routerLink="/manage_cycles_instances" routerLinkActive="active"> Manage cycles instances</a>
</nav>
<router-outlet></router-outlet>
<div *ngIf="router = '/dr3-interface'">
<h2><d-table></d-table></h2>
</div>
<br/>
<form-upload></form-upload>
<br/>
<list-upload></list-upload>
Run Code Online (Sandbox Code Playgroud)
app-routing.module.ts:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { DataTableComponent } from './datatable/data-table.component';
const appRoutes: Routes = [
{ path: 'manage_cycles_instances', component: DataTableComponent },
/* TO DO : page error
{ path: …Run Code Online (Sandbox Code Playgroud) 我正在尝试将一个string从子组件发送到他的父组件。
这是孩子:
//imports...
@Component({
selector: 'child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.css'],
providers: [ChildService]
})
export class DataTableComponent implements OnInit {
constructor(private http: HttpClient, private childService : ChildService) {}
myMap = new Map<string, ISomeInterface>();
currentSelection: string;
@Output() sendDataEvent = new EventEmitter<string>();
sendData() {
console.log("sending this data: " + this.myMap.get(this.currentSelection).name);
this.sendDataEvent.emit(this.myMap.get(this.currentSelection).name);
}
}
Run Code Online (Sandbox Code Playgroud)
这是父母:
html->
<d-table (sendDataEvent)="receiveBusinessCycle(event)"></d-table>
Run Code Online (Sandbox Code Playgroud)
打字稿->
//imports...
@Component({
selector: 'parent',
templateUrl: './parent.component.html',
styleUrls: ['./parent.component.css'],
providers: [ParentService]
})
export class MyParentComponent {
totoName: string;
constructor(private parentService : ParentService) { } …Run Code Online (Sandbox Code Playgroud) 今天我有这个代码,基本上当我点击详细信息按钮时,它会打开一个mat-menu但不知何故我无法修改菜单的填充或宽度值:
<div id="box-upload" [hidden]="hiddenBoxUpload" *ngIf="filesExist">
<button mat-raised-button color="primary" [matMenuTriggerFor]="listFiles">Details</button>
<mat-menu class="filesList" #listFiles="matMenu">
<div *ngFor="let key of listkey">
<div *ngIf="detailsExist">
<!-- some stuff like mat-progress-bar and span>
</div>
</div>
</mat-menu>
</div>
Run Code Online (Sandbox Code Playgroud)
css代码:
.filesList {
width: auto;
padding: 15px;
}
Run Code Online (Sandbox Code Playgroud)
更改 a 的默认填充和宽度的方法是mat-menu什么?
我知道slice()数组,现在要“切片”我正在使用此代码的地图:
const map = new Map([[1,"a"],[2,"b"]])
var arrayTmp = Array.from(map).slice(0,1);
var myMap = new Map();
arrayTmp.forEach(value => {
myMap.set(value[0], value[1]);
});
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我想知道是否有一些现有的本地方法来获得更简洁的代码?
我正在使用一个小processconf.js工具configuration.json从多个.json文件构建一个文件.
这里是我使用的命令:
node processconf.js file1.json file2.json > configuration.json
Run Code Online (Sandbox Code Playgroud)
我正在使用cmd片刻,但今天我尝试使用Powershell并以某种方式从相同的文件和相同的命令我有不同的结果.
一个文件是33kb(cmd)另一个66kb(powershell),查看文件他们有完全相同的行,我找不到任何视觉差异,为什么会这样?
我想我部分理解了生命周期的概念,但我在递归类型定义中遇到了问题:
struct Person<'a> {
name: String,
children: Vec<&'a mut Person<'a>>,
birth: String,
death: String,
religion: String,
genre: String,
}
impl Person<'_> {
fn add_children(&'_ mut self, p: &'_ mut Person<'_>) {
self.children.push(p);
}
}
Run Code Online (Sandbox Code Playgroud)
编译器说:
error[E0312]: lifetime of reference outlives lifetime of borrowed content...
--> src/lib.rs:12:28
|
12 | self.children.push(p);
| ^
|
note: ...the reference is valid for the lifetime `'_` as defined on the impl at 10:13...
--> src/lib.rs:10:13
|
10 | impl Person<'_> {
| ^^
note: …Run Code Online (Sandbox Code Playgroud) angular ×6
html ×4
typescript ×3
angular5 ×2
css ×2
java ×2
javascript ×2
borrowing ×1
build ×1
cmd ×1
comparator ×1
dependencies ×1
deployment ×1
eslint ×1
event-loop ×1
httpserver ×1
java-8 ×1
lifetime ×1
material ×1
maven ×1
node.js ×1
powershell ×1
promise ×1
react-hooks ×1
reactjs ×1
reference ×1
rust ×1
sorting ×1
windows ×1