在我们学校的最新项目中,我遇到了一些问题.我想观察一个新条目的路径,路径是由文件控制器按钮选择的,但是如果我选择任何文件,整个窗口会冻结...我猜它被冻结了,因为"observePath"方法被调用但是我不知道我知道如何解决这个问题.
这是代码:
public void start() {
public Path absolutePath;
final Label labelSelectedDirectory = new Label();
Button btnOpenDirectoryChooser = new Button();
btnOpenDirectoryChooser.setText("Open DirectoryChooser");
btnOpenDirectoryChooser.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
DirectoryChooser directoryChooser = new DirectoryChooser();
File selectedDirectory =
directoryChooser.showDialog(primaryStage);
if(selectedDirectory == null) {
labelSelectedDirectory.setText("No Directory selected");
}else{
labelSelectedDirectory.setText(selectedDirectory.getAbsolutePath());
absolutePath = selectedDirectory.toPath();
try {
observePath();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
});
public void observePath() throws IOException, InterruptedException {
WatchService watcher = FileSystems.getDefault().newWatchService();
FileSystem fs …Run Code Online (Sandbox Code Playgroud) 这些是我在 Router.js 中的主要路由
const Routes = () => {
return (
<Switch>
<Route path="/" exact component={HomePage} />
<Route path="/dashboard" component={Dashboard} />
</Switch>
);
}
Run Code Online (Sandbox Code Playgroud)
这些是我在主页下的嵌套路由。现在仪表板和主页正在运行,但忘记密码和注册不起作用。我只能看到没有错误的空白页。
render() {
const {match} = this.props;
return (
<div className="container home-grid">
<div className="featured">
<Featured />
</div>
<div className="home-forms">
<div className="logo">
<Logo />
</div>
<TransitionGroup className="route-page">
<CSSTransition
key={location.pathname}
timeout={{ enter: 800, exit: 800 }}
classNames="page"
>
<section className="route-section">
<Switch>
<Route exact path={match.path} component={SignIn}/>
<Route path={`${match.path}forgot-password`} component={ForgotPassword} />
</Switch>
</section>
</CSSTransition>
</TransitionGroup>
<div className="footer-text">
<Text specialClass="footer"></Text>
</div> …Run Code Online (Sandbox Code Playgroud) 如何在 module.exports 参数中创建回调函数。我正在尝试做如下类似的事情,我想知道如何实现回调函数。
模块.js
module.exports = (a, b, callback) => {
let sum = a+b
let error = null
//callback
}
Run Code Online (Sandbox Code Playgroud)
应用程序.js
const add = require(./module.js)
add(1,2, (err, result) => {
}
Run Code Online (Sandbox Code Playgroud) 我试图在构造函数中设置一个可以由嵌套函数表达式调用的变量.不太确定如何做到这一点
var test = function() {
var a;
function test(a, b, c) {
this.a = a;
this.b = b;
this.c = c;
}
test.getvariableA = function() {
//not returning a variable that is supposed to be set by the constructor
console.log(this.a);
};
return test;
}();
var t = new test("pizza", "pasta", "steak");
//does not return the variable
test.getvariableA();
//this returns the variable
console.log(t.a);Run Code Online (Sandbox Code Playgroud)
test.getvariableA();
这应该返回构造函数设置的变量.也许我对另一种语言感到困惑,谢谢你提前帮忙.
我正在使用Django detailview。最初,我使用URL模式
url(r'^todo/details/(?P<pk>[\d]+)', views.todoDetailView.as_view(), name='detail_todo'),
Run Code Online (Sandbox Code Playgroud)
我的看法是
class todoDetailView(DetailView):
model = models.todo
Run Code Online (Sandbox Code Playgroud)
工作正常。
在第二种情况下,我的网址是
url(r'^todo/details/(?P<id>[\d]+)', views.todoDetailView.as_view(), name='detail_todo'),
Run Code Online (Sandbox Code Playgroud)
这次,我修改了观点
class todoDetailView(DetailView):
model = models.todo
# context_object_name = 'todo_detail'
def get_object(self, **kwargs):
print(kwargs)
return models.todo.objects.get(id=self.kwargs['id'])
Run Code Online (Sandbox Code Playgroud)
效果很好,我将第二种情况修改为
class todoDetailView(DetailView):
model = models.todo
# context_object_name = 'todo_detail'
def get_queryset(self):
return models.todo.objects.get(id=self.kwargs['id'])
Run Code Online (Sandbox Code Playgroud)
然后我得到一个错误,
通用详细信息视图todoDetailView必须使用对象pk或子弹调用。
我知道没有提供适当的子弹或pk。因此,最初我添加了get_object()(它可以工作),但是get_queryset()不起作用。他们的工作有什么区别?
而且,如果用户仅根据这些信息获取详细信息,我在StackOverflow上读到
可以使用
slug_field = 'param_name'
slug_url_kwarg = 'param_name'
Run Code Online (Sandbox Code Playgroud)
链接- 通用详细信息视图ProfileView必须使用对象pk或子弹调用
任何人都可以向我解释get_object()和get_queryset()的实际工作方式(如果可能的话,还要get_slug_field())
以及条款slug_field和slug_url_kwarg
提前致谢
我的项目模块包含很多练习题,从我选择并试图解决的一个问题,下面是问题.
给定一组数字,以产生最大值的方式排列它们.例如,如果给定的数字是{54,546,548,60},则排列6054854654给出最大值.输入:第一行包含整数N,下一行包含由空格分隔的N个整数.输出:打印使用给定数字可以获得的最大数量.约束:1 <= N <= 1000 1 <=数<= 1000000
HTML:
Enter Number: <input type="text" id="userinput" class="clr"/> <br>
<br>
Largest Value: <input type="text" id="out" class="clr"/> <br> <br>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
function myFun() {
let b = document.getElementById("userinput").value;
let c = b.split(" ");
var maxCombine = (a) => +(a((x, y) => +("" + y + x) - +("" + x + y)).join(''));
document.getElementById("out").value = ([
c
].map(a));
};
Run Code Online (Sandbox Code Playgroud)
我在为错误的声明变量运行脚本时遇到错误.请提出建议.
错误:
Uncaught ReferenceError: a is not defined
at myFun (lagnum.html:26)
at HTMLButtonElement.onclick
Run Code Online (Sandbox Code Playgroud)