在反应中(在钩子之前),当我们设置状态时,我们可以在状态被设置为这样后调用一个函数:
this.setState({}, () => {//Callback})
Run Code Online (Sandbox Code Playgroud)
钩子相当于什么?
我尝试这样做
const [currentRange, setCurrentRange] = useState("24h");
setCurrentRange(someRange, () => console.log('hi'))
Run Code Online (Sandbox Code Playgroud)
但这没有用
有人知道解决方案吗?
嗨,对于不同的 javafx 应用程序,我一直在测试警报,并且唯一在按下警报框的“X”按钮时不起作用。
我在下面添加了一个代码,但如果您没有时间运行它,这里是一个 GIF,用于解释我的警报框有什么问题:https ://giant.gfycat.com/GeneralUntimelyBluewhale.webm
我不太确定如何将 gif 上传到实际帖子中,对此我深表歉意。
有没有办法解决这个问题?
谢谢
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Playground extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
VBox root = new VBox(100);
root.setPadding(new Insets(10));
root.setAlignment(Pos.CENTER);
Button button = new Button("Alert");
button.setOnAction(event -> {
ButtonType goodButton = new ButtonType("Good");
ButtonType badButton = new ButtonType("Bad");
Alert alert = new …Run Code Online (Sandbox Code Playgroud) 假设我在同一控制器中有一个可观察的列表和一个按钮
private ObservableList<NameItem> _selectedList = _database.getONameList();
@FXML
private Button nextButton;
Run Code Online (Sandbox Code Playgroud)
我如何做到只有在ObservableList大于0时才启用按钮,否则将其禁用?我可以使用绑定属性来设置它吗?
我尝试使用此:https : //stackoverflow.com/a/38216335/5709876
但是它对我没有用..