数组问题(我认为) [英] Problem with arrays (I think)

查看:74
本文介绍了数组问题(我认为)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有点困惑的是我正在写的剧本。我正在做一个脚本,它会自动生成一系列命令,然后由第三方应用程序执行。非常简单的解释,我正在生成一系列命令,然后将其导出为类似txt的文件。


我之前没有遇到任何问题,但现在我做了发生了一些奇怪的事情。我实现了一个排序功能,当我独立使用它时似乎工作正常。但是当我将代码复制到我的大脚本中时,它就不再起作用了。我检查了脚本的重复名称,但没有。我在独立脚本中唯一不同的是,我在不同函数的数组中创建新项目。但是在独立脚本中,它也在一个函数中并且在那里工作得很好。


可能是因为我不应该把阵列分成几块?虽然当我查看代码时,我不认为我做错了什么。


这是独立版本,工作正常:

Hi guys,

I''m a bit puzzled by a script I''m trying to write. I''m doing a script which wil automatically generates a series of commands which can then be executed by a third party application. Very simply explained, I''m generating a series of commands and I export that to a txt-like file.

I''ve done this before without any problems but now I''ve got something strange going on. I implemented a sort function which seems to work fine when I use it stand-alone. But when I copy the code into my big script, it doesn''t work anymore. I checked the script for duplicate names but there aren''t any. The only thing what I''m doing different then in the stand-alone script, is that I create new items in an array in different functions. However in the stand-alone script that is also in a function and there it works perfectly.

Could it be because I''m not supposed to split arrays in pieces? Although when I look at the code, I don''t think I''m doing anything wrong with it.

This is the stand-alone version which works fine:

展开 | 选择 | Wrap | 行号

推荐答案

更新


大家好,


经过几个小时的进一步测试和注视代码后,我只能得出结论,这是非常奇怪的......


向数组中添加内容现在已被移动到一个功能中。


我已经放了一个测试按钮要求这个功能。这种方式似乎有效。但是,当我从另一个函数内部调用此函数时,它不起作用。虽然它的功能相同。


所以我想,也许主函数中有一个错误,我称之为另一个函数。所以我创建了第二个函数,它只是出于调试原因而显示一个弹出窗口。因此,当我测试它时,我得到了弹出窗口,但数据没有传递给数组。所以我肯定他正在执行它,但它不工作。


所以我的问题是:为什么在使用按钮调用函数时它可以工作但是不是当我从另一个函数里面调用函数的时候吗?


任何天才都知道答案那个吗?


为我上床睡觉。谢谢你们。
UPDATE

Hi guys,

After a few hours of further testing and gazing at code I can only conclude that this is something very strange...

Adding stuff to the array has now been moved inside a function.

I''ve put a test button in place which calls for this function. And this way it seems to work. However, when I call this function from inside another function, it doesn''t work. Although it''s the same function.

So I thought, maybe there''s an error in the main-function from where I''m calling this other function. So I created a second function which just shows a popup just for debugging reasons. So when I tested it, I get the popup but the data isn''t passed to the array. So I''m sure he''s executing it but it diesn''t work.

So my question is: Why does it work when using a button to call the function but not when I just call the function from inside another function ?

Any genius know the answer to that one?

Off to bed for me. Thanks guys.


更新2


我做了最后一次快速测试。


因为我的test2(带弹出窗口的那个)正在工作,我将test1的内容复制到test2中。我让函数运行,我得到了弹出窗口,但没有数据被传递给数组。


这是我生命中的第一次,Javascript已经超过了我...


现在真的下床了。
UPDATE 2

I did just one last quick test.

Since my test2 (the one with the popup) was working, I copied the contents of test1 into test2. I let the function run and I get the popup but no data is being passed to the array.

For the first time in my life, Javascript has outsmarted me ...

Now really off to bed.


嗨...


你应该使用:

hi ...

you should use:

展开 | 选择 | Wrap | 行号


这篇关于数组问题(我认为)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆