且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么这个对象属性未定义?

更新时间:2023-02-22 16:16:24

我已经解决了这个问题。基本上,有问题的对象( that.data [0] .cards )的属性由函数 a()$ c $创建c>在处理完必要XML文件的所有AJAX请求之后运行。我允许请求以异步方式运行,如果 a()应该使用计数器在 success 回调函数中确定已经调用。

I've solved the problem. Basically, the object in question (that.data[0].cards) has its properties created by a function a() that runs after all the AJAX requests for the necessary XML files have been processed. I allow the requests to run asynchronously, using a counter to determine in the success callback function if a() should be called yet.

a()运行后,函数 b()应该在 that.data [i] .cards 上执行操作。但是, b() a()之前运行,因为 a( )依赖异步请求。因此,解决方案只是使 a()调用 b()

After a() runs, function b() is supposed to perform operations on that.data[i].cards. However, b() was running prior to a() being called because of a()'s reliance on the asynchronous requests. So the solution was simply to make a() call b().

所以这对我来说是一个非常简单的错误。让它如此混乱的原因是将 .cards 记录到控制台的事实向我展示了实际上对象已经构建,实际上还没有。因此,控制台向我提供了不正确 - 或至少不清楚 - 的信息。

So this turned out to be a pretty simple mistake on my part. What made it so confusing was the fact that logging that.data[0].cards to the console showed me that in fact the cards object had already been built, when in fact it had not yet. So the console was providing me with incorrect--or at least unclear--information.

感谢大家昨晚的帮助!赞成四处:)

Thanks for everyone's help last night! Upvotes all around :)