我编写了下面的 react 组件来处理我使用 react 制作的扫雷艇克隆的难度级别。
我使用单选按钮作为难度输入,并希望根据所做的选择设置组件的状态。
我的问题是每次更改选择时,状态都会更新为我之前的选择而不是当前选择的值。例如,在页面加载期间,所选难度为“简单”。当我将难度更改为“困难”时,状态仍然显示初始设置,即“简单”(我做了状态的控制台日志来验证这一点)。
请帮忙。
import React, {Component} from 'react';
class Difficulty extends Component{
state = {
height: 8,
width: 8,
mines: 10,
};
setDifficulty(event){
let selectedDifficulty = event.target.value;
if (selectedDifficulty === "Easy") {
this.setState({
height: 8,
width: 8,
mines: 10,
});
}
if (selectedDifficulty === "Medium") {
this.setState({
height: 12,
width: 12,
mines: 20,
});
}
if (selectedDifficulty === "Hard") {
this.setState({
height: 16,
width: 16,
mines: 40,
});
}
this.props.updateDifficulty(this.state);
}
render(){
return(
<div className="game-difficulty"> …Run Code Online (Sandbox Code Playgroud) 我有一个带有console.log("Hello World"). 我想从我的终端运行它(我在 Mac 上)。我安装了节点,并采取以下步骤 -
但是我在终端中没有看到控制台语句(Hello World)。
有人可以帮我从终端运行javascript(或告诉我我做错了什么)?
PS:我已经检查了这个线程,但我的问题仍然存在。
我的 angular 2 应用程序中有一个组件,它有一个下拉列表和一个数据表。根据从下拉列表中选择的名称,我想在数据表中显示详细信息。
HTML -
<div>
<select [(ngModel)]="selectedName">
<option *ngFor="let name of nameList" value= {{name.firstName}} >
{{name.firstName}}
</option>
</select>
<button id="submitName" (click)="getData()">Go</button>
</div>
<table #myTable [dtTrigger]="dtTrigger" datatable class="row-border hover">
<thead>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last Name</th>
<th>Middle Name</th>
</tr>
</thead>
<tbody *ngIf="retrievedNames">
<tr *ngFor="let name of retrievedNames">
<td>{{name.id}}</td>
<td>{{name.firstName}}</td>
<td>{{name.lastName}}</td>
<td>{{name.middleName}}</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我的组件.ts
import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
import { NetworkService } from './../services/network.service';
import { Subject } from …Run Code Online (Sandbox Code Playgroud)