将文本复制并粘贴到ios模拟器中(Copy paste text into iOS simulator)
这必须在某个地方记录,但我找不到。
在我使用iPad模拟器的应用程序中,有一个文本框,我希望用户粘贴文本。 在现实世界中,用户将文本从Safari地址复制到文本字段。 但是我试图在ios ipad模拟器中做到这一点,只是部分结果。
在我重新启动该应用程序后,我可以立即使用Mac的“
Edit|Paste Text
菜单或使用Shift-Command-V将Edit|Paste Text
粘贴到文本框中(但不能仅使用“Edit|Paste
,但这是确定)。 Shift的需要是令人讨厌的,但我可以忍受。但是,如果我尝试在Mac上复制另一个URL,然后再次
Edit|Paste Text
,甚至使用模拟器上的Paste
泡泡,我不会得到新的文本,而不是原始文本。那是常见的吗? 这是模拟器的一个功能,它没有连接到主机上的剪贴板?
This must be documented somewhere, but I can't find it.
In my app using the iPad simulator there is a textfield into which I want the user to paste text. In the real world the user will copy the text from Safari address into the textfield. But I am trying to do that in the ios ipad simulator, but with only partial results.
After I reRUN the app, I can immediately paste text into the textfield with the Mac's
Edit|Paste Text
menu or with Shift-Command-V, (but not with justEdit|Paste
, but that's Ok). The need for the Shift is annoying but I can live with it.But then if I try to copy another URL on the Mac and then again,
Edit|Paste Text
or even use thePaste
bubble on the simulator, I don't get the new text, but the original text.Is that common? Is that a feature of the simulator that it is not connected live to the clipboard on the host computer?
原文:https://stackoverflow.com/questions/15188852
最满意答案
只有在
Promise.all
解析每个文件后才Promise.all
解析。 此外,只有在目录中的每个文件完成后才需要解析每个目录promise:let readDirectory = function(dirname) { return new Promise((resolveAll, rejectAll) => { fs.readdir(dirname, (err, files) => { if (err) rejectAll(err); }) }).then((files) => { const filesPromises = files.map(file => ( new Promise((resolveFile, rejectFile) => { fs.stat(`${dirname}/${file}`, (err, stats) => { if (err) rejectFile(err); if (stats.isDirectory()) { readDirectory(`${dirname}/${file}`) .then(resolveFile); .catch(rejectFile); } else { resolveFile(console.log(file)); } }) }) )); return Promise.all(filesPromises).then(resolveAll); }); }
请注意,这很难理解 - 使用
async
/await
会更好,例如:let readDirectory = async function(dirname) { const files = await new Promise((resolve, reject) => { fs.readdir(dirname, (err, files) => { if (err) reject(err); resolve(files); }); }); const filesPromises = files.map(async (file) => { const stats = await new Promise((resolve, reject) => { fs.stat(`${dirname}/${file}`, (err, stats) => { if (err) reject (err); else resolve(stats); }); }); if (stats.isDirectory()) await readDirectory(`${dirname}/${file}`); else console.log(file); }); return Promise.all(filesPromises); }
You need to resolve only after
Promise.all
resolves over every file. Also, you need to resolve each directory promise only after each file in the directory is finished:let readDirectory = function(dirname) { return new Promise((resolveAll, rejectAll) => { fs.readdir(dirname, (err, files) => { if (err) rejectAll(err); }) }).then((files) => { const filesPromises = files.map(file => ( new Promise((resolveFile, rejectFile) => { fs.stat(`${dirname}/${file}`, (err, stats) => { if (err) rejectFile(err); if (stats.isDirectory()) { readDirectory(`${dirname}/${file}`) .then(resolveFile); .catch(rejectFile); } else { resolveFile(console.log(file)); } }) }) )); return Promise.all(filesPromises).then(resolveAll); }); }
Note that this is pretty difficult to make sense of - you'll be far better off using
async
/await
instead, something like this:let readDirectory = async function(dirname) { const files = await new Promise((resolve, reject) => { fs.readdir(dirname, (err, files) => { if (err) reject(err); resolve(files); }); }); const filesPromises = files.map(async (file) => { const stats = await new Promise((resolve, reject) => { fs.stat(`${dirname}/${file}`, (err, stats) => { if (err) reject (err); else resolve(stats); }); }); if (stats.isDirectory()) await readDirectory(`${dirname}/${file}`); else console.log(file); }); return Promise.all(filesPromises); }
相关问答
更多-
Javascript递归承诺(Javascript Recursive Promise)[2024-02-26]
为了使递归与承诺一起工作,您通常希望将所有递归承诺链接到它们的调用者。 为此,您必须从您的.then()处理程序返回任何承诺,以便将它们链接到原始文件。 这也往往会消除你的承诺反包装现有的承诺与手动创造的承诺,充满了问题的模式。 这是一种做法: function loadReports(personEmail, list) { return getAccessTokenPromise().then(access_token => { list.push(personEmail); ... -
如何在JavaScript中使用递归函数时处理promise(How to handle promises while using recursive functions in JavaScript)[2024-02-13]
只有在Promise.all解析每个文件后才Promise.all解析。 此外,只有在目录中的每个文件完成后才需要解析每个目录promise: let readDirectory = function(dirname) { return new Promise((resolveAll, rejectAll) => { fs.readdir(dirname, (err, files) => { if (err) rejectAll(err); }) }).then((fil ... -
复杂功能的承诺(Promises in complex functions)[2023-09-05]
拒绝承诺不会奇迹般地阻止函数执行其余的代码。 拒绝之后,你应该从函数返回: if (err) { deferred.reject(new Error(err)); return; } 或更短: if (err) { return deferred.reject(new Error(err)); } Rejecting a promise doesn't miraculously stop the function from executing the rest of its code. So ... -
forEach接受一个回调函数,这是一个匿名函数,而this匿名函数内部是指非严格模式下的window或严格模式下undefined window 。 你需要绑定上下文: Object.keys(value).forEach(function (keydata) { let obj = value[keydata]; this.getData(keydata,value[keydata]); console.log(key,obj,obj instanceof Object) ...
-
你的问题代表了这两个功能,我添加了注释来标记它们: function promiseToProcessElement(id,num,callbackProcessElement,matrix) { return new Promise((resolve, reject) => { var result=callbackProcessElement(id, num,matrix); resolve(result);//You resolve the promise without waiting. ...
-
您尝试使用承诺与新的连接似乎有点误导。 您将希望从connect()返回一个承诺,以便您可以使用它来知道服务器何时连接。 看起来你可能想要这样的东西: function connect() { return new Promise(function(resolve, reject) { var server = new WebSocket('ws://mysite:1234'); server.onopen = function() { res ...
-
如何在递归函数中处理JavaScript中的回调?(How to handle callbacks in JavaScript within recursive functions?)[2023-09-13]
正如这里详细解释的那样 你需要重构你的代码。 不知何故,似乎不是在异步(通常是延迟的)函数中使用递归来搜索基于树的或分层数据模型的正确方法。 我认为这应该是这样做的方式: 将逻辑分成几个函数 使用“延迟加载”以避免重复调用getChilden() 使用递归并定义新的嵌套函数回调 将for循环重构为递归 查看我未经测试的代码以显示我的意思: function compare(lhs, rhs, callback, index, lhsChilds, rhsChilds){ // Not equ ... -
但这似乎是一种反模式的承诺 确实是: 延期的反模式 ! 您不需要构造新的延迟,您可以使用then 链接您的操作,映射和错误。 您只需抛弃以下内容即可拒绝退回的承诺 : function doTaskWithUserId(userId) { return getUser(userId).then(function(user) { // ^^^^^^ if (user.activated) { return doTask(user); } els ...
-
没有看到您的实际代码,我们无法专门回答。 听起来有点熟? 你如何保持对Promises按时发布后续代码的适当控制? 答案始终是不解决链中的第一个承诺,直到您准备好执行事物并构建您的承诺链,以便在他们等待的事情得到妥善解决之前,依赖事物不会被执行。 如果某件事情过早执行,那么你要么过早地打电话,要么你的承诺结构不正确。 没有看到您的实际代码,我们无法确切知道。 一个常见的错误是: someAsyncOperation().then(someOtherAync()).then(...) 应该是: someAs ...
-
多个条件异步递归函数和jQuery承诺(Multiple conditional asynchronous recursive functions and jQuery promises)[2021-11-27]
在Sandeep Nayak的帮助下,我得到了它的工作(见上面的评论)。 我以为我发布了伪代码的工作版本给遇到类似问题的任何人。 我基本上添加了两个级别的promises(外部和内部),如果所有内部promise都被解析,外部promise将被解析。 整理代码可能有余地,但它可以正常工作。 function wrapperFunction(success,error) { var level = 0; var result = []; var outerPromises = []; ...