node-webkit如何解析'事件参数
node-webkit How to parse 'open' event parameter?
我需要一个包含所有参数的数组,比如gui.App.argv中的值
是否包含一些函数来解析这个?
function openfile(cmdline){
console.log('command line: ' + cmdline);
}
openfile(gui.App.argv); //my file.txt, my file.txt (this is what I need)
gui.App.on('open', function(cmdline) {
openfile(cmdline); //app.exe --original-process-start-time=13049249391168190 "my file.txt" "my file2.txt"
});
我刚刚遇到了同样的问题,下面是我如何解决的:
// Listen to `open` event
gui.App.on('open', function (cmdline) {
// Break out the params from the command line
var arr = /(.*)--original-process-start-time'=('d+)(.*)/.exec(cmdline);
// Get the last match and split on spaces
var params = arr.pop().split(' ');
console.log('Array of parameters', params);
});
只要它们不改变事件的输出结构(即——original-process-start-time标志),这将有效。但如果他们这样做,我会考虑使用进程。也许execPath
我的解决方案:
1. 将引号中的空格替换为"&,"
(HTML空间)。2. 用空格分隔字符串。
3.替换",
gui.App.on('open', function(cmdline) {
cmdline = cmdline.replace(/"([^"]+)"/g, function(a) {
return a.replace(/'s/g, " ");
}).split(' ');
for (var i = 0, length = cmdline.length, arg = '', args = []; i < length; ++i) {
arg = cmdline[i].replace(/ /g, ' ');
// Filter by exe file and exe args.
if (arg === '"' + process.execPath + '"' || arg.search(/^'-'-/) === 0) continue;
args.push(arg);
}
console.log(args);
});
在0.14上工作。x, 0.15.x。
相关文章:
- Firefox中的JavaScript事件参数
- 将参数传递给 jQuery .click WHILE 保留事件参数
- onWindowResize事件参数使用Three.js
- 如何在 redis 中将 JS 对象传递给它自己的事件参数 - 连接事件上的哨兵
- 在剑道的自定义绑定器中添加事件参数
- 加载处理程序上的事件参数
- 将jQuery触发器中的事件参数发送到iframe
- 在ExtJS中访问事件参数
- node-webkit如何解析'事件参数
- 如何用间隔刷新鼠标向下的事件参数
- Javascript/JQuery 事件参数.我不明白这个“e”论点是什么或做什么
- Firefox onkeypress事件没有传递事件参数
- 我如何从JS函数中获得触发事件而不传递事件参数
- 如何获取getUIKit事件参数的className
- 事件参数及其用途
- 在全局变量中存储mousemove事件参数可能会导致性能问题
- 为什么stopPropagation在回调中使用事件参数,而不是使用'this'
- 文档.ie8和IE7未定义onmouseover和onmouseout事件参数
- 在使用 ClientScript.GetPostBackEventReference 时将事件参数从 javascrip
- 如何为复选框单击事件使用自定义事件参数