我想在我的Intranet页面上实现一个简单的文件上传,尽可能小的设置.
这是我的HTML部分:
<input id="sortpicture" type="file" name="sortpic" />
<button id="upload">Upload</button>
Run Code Online (Sandbox Code Playgroud)
这是我的JS jquery脚本:
$("#upload").on("click", function() {
var file_data = $("#sortpicture").prop("files")[0];
var form_data = new FormData();
form_data.append("file", file_data);
alert(form_data);
$.ajax({
url: "/uploads",
dataType: 'script',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(){
alert("works");
}
});
});
Run Code Online (Sandbox Code Playgroud)
在网站的根目录中有一个名为"uploads"的文件夹,具有"users"和"IIS_users"的更改权限.
当我选择具有文件格式的文件并按下上传按钮时,第一个警报返回"[object FormData]".第二个警报没有被调用,"uploads"文件夹也是空的!?
有人可以帮助我找出错误吗?
下一步应该是,用服务器端生成的名称重命名文件.也许有人可以给我一个解决方案.
如何仅选择其父级树中没有某个类的父级的子级?
这不起作用:
div:not(.dontSelect) .child
Run Code Online (Sandbox Code Playgroud)
div:not(.dontSelect) .child
Run Code Online (Sandbox Code Playgroud)
div {
background-color: red;
padding: 5px;
}
div:not(.dontSelect) .child {
background-color: green;
padding: 5px;
}Run Code Online (Sandbox Code Playgroud)
下面是我捕获通知的代码.我不明白为什么onNotificationPosted没有被解雇.
我从"设置">"安全"中获取应用程序通知访问权限,而MyNotifService中的onCreate也被解雇,但onNotificationPosted未被解雇.
我错过了什么或做错了什么?
从我的MainActivity的onCreate()函数:
Intent intent = new Intent(this, MyNotifService.class);
this.startService(intent);
Run Code Online (Sandbox Code Playgroud)
我的服务代码扩展了NotificationListenerService:
@SuppressLint("NewApi")
public class MyNotifService extends NotificationListenerService {
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
super.onNotificationPosted(sbn);
Log.v("focus", "in onNotificationPosted() of MyNotifService");
}
@Override
public void onCreate() {
super.onCreate();
Log.v("focus", "in onCreate() of MyNotifService");
}
}
Run Code Online (Sandbox Code Playgroud)
公共类MyNotifService扩展NotificationListenerService {
<service android:name="com.mavdev.focusoutfacebook.notifications.MyNotifService"
android:label="@string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
在清单文件中,我有这个:
Intent intent = new Intent(this, MyNotifService.class);
this.startService(intent);
Run Code Online (Sandbox Code Playgroud) 根据文档,任何nodejs Express中间件功能都可以替换为App或Router实例:
由于路由器和应用程序实现了中间件接口,因此您可以像使用任何其他中间件功能一样使用它们。
这是我使用的一些通用错误处理:
express()
.use('/test', new TestRouter())
.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send(err.message);
})
.listen(PORT);
Run Code Online (Sandbox Code Playgroud)
我尝试用错误处理路由器替换错误处理,但现在回调永远不会执行,并且 Express 使用它的默认错误处理。
const handler = new express.Router();
handler.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send(err.message);
});
express()
.use('/test', new TestRouter())
.use(handler)
.listen(PORT);
Run Code Online (Sandbox Code Playgroud)
为什么这没有按预期工作,我该如何解决它?
我正在尝试使用数组和箭头函数的限制,并尝试将此 reduce 函数转换为箭头函数:
var monthsById = months.reduce(function(result, month) {
result[month.Id] = month;
return result;
}, {});
Run Code Online (Sandbox Code Playgroud)
但是我无法返回地图,因为result[month.Id] = month;将返回月份而不是像这种方法中的地图:
var monthsById = months.reduce((byId, month) => byId[month.Id] = month, {});
Run Code Online (Sandbox Code Playgroud)
所以我正在寻找一个单一的语句,它设置值并返回对象。(new Map()不是一个选项,因为我需要它的常规{}格式)。
var monthsById = months.reduce(function(result, month) {
result[month.Id] = month;
return result;
}, {});
Run Code Online (Sandbox Code Playgroud)