我无法让jQuery专注于输入字段。我忽略了一些明显的东西吗?在Firefox 56中,此代码对我不起作用。此外,在Chrome中,它随机无法正常工作 - 如果我模糊字段并重新加载代码段,它就不会聚焦。从来没有遇到过这个问题。
public async Task BulkUpsertData(List<MyObject> newUpsertDatas)
{
var usernames = newUpsertDatas.Select(p => p.Username);
var filter = Builders<MyObject>.Filter.In(p => p.Username, usernames);
//Find all records that are in the list of newUpsertDatas (these need to be updated)
var collection = Db.GetCollection<MyObject>("MyCollection");
var existingDatas = await collection.Find(filter).ToListAsync();
//loop through all of the new data,
foreach (var newUpsertData in newUpsertDatas)
{
//and find the matching existing data
var existingData = existingDatas.FirstOrDefault(p => p.Id == newUpsertData.Id);
//If there is existing data, preserve the date created (there are other fields I preserve)
if (existingData == null)
{
newUpsertData.DateCreated = DateTime.Now;
}
else
{
newUpsertData.Id = existingData.Id;
newUpsertData.DateCreated = existingData.DateCreated;
}
}
await collection.DeleteManyAsync(filter);
await collection.InsertManyAsync(newUpsertDatas);
}
$(document).ready(function() {
$('#focus').focus();
});
更新:关闭浏览器并重新打开,问题神奇地消失了。不知何故,Firefox失去了响应此事件的能力 - 我将这归结为浏览器或操作系统错误。留下问题可能对其他人有帮助。