ReferenceError: Error #1065: Variable is not defined when searching for a node by attribute

a 夏天 提交于 2020-01-06 19:27:17

问题


I've done this lot of times, but now I'm missing something.... I'm searching for a node by looking for a value in an attribute.

If I try to trace:

 xmlQuestStructure.page[activePageIndex].label.@priority

The trace it's ok, and I can read High, Medium, Low (the values I'm expecting).

But if I try to trace this (where calculatedPriority is a String with value High, Medium or Low)

 xmlQuestStructure.page[activePageIndex].label.(@priority == calculatedPriority)

I get ReferenceError: Error #1065: Variable priority is not defined

What am I doing wrong? Thx for your help!


回答1:


Most likely, your problem is that one of your label nodes DOESN'T have a priority attribute defined. When you use @ in e4x, it will throw an error if it comes to a XML node that doesn't have the attribute specified.

If there is a possibility that your XMLnode could have the attribute omitted, then instead of using '@', use attribute().

So in your case, you could do this:

xmlQuestStructure.page[activePageIndex].label.(attribute("priority") == calculatedPriority);

using attribute() is more passive, and will ignore the node if it doesn't have the specified attribute, instead of throwing an error.



来源:https://stackoverflow.com/questions/12587847/referenceerror-error-1065-variable-is-not-defined-when-searching-for-a-node-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!