我使用jQuery data()来存储元数据,但似乎jQuery 1.4.4和1.4.3都有问题。有些部件可以工作,其他部件不起作用。jQuery data()返回undefined
举例来说,我有
const UimConst = {
NODE_OBJECT: "nodeObject",
CHILDREN: "children",
PARENT: "parent",
SID: "sid",
COUNT: "count",
EXCLUDE: "exclude",
PARENT_COUNT: "pcount",
HEIGHT: "UimHeight"
};
Workspace.prototype.findAncestor = function(element){
if(this.ancestor == null){
this.ancestor = $(element);
this.ancestor.data(UimConst.HEIGHT, 0);
} else {
...
}
其中元素是DOM元素。然后,我得到我存储的值如下,
var height = this.ancestor.data(UimConst.HEIGHT);
logger.debug("Current UI module height " + height);
不幸的是,返回值是未定义的。
为了进一步追查问题,我改变了代码是
if(this.ancestor == null){
this.ancestor = $(element);
this.ancestor.data(UimConst.HEIGHT, 0);
logger.debug("After set the ancestor height, the value is " + this.ancestor.data(UimConst.HEIGHT));
} else {
日志中的返回值是“不确定”的可能。真的很沮丧。
我在一些其他地方使用数据(),他们工作得很好。不知道发生了什么事。 任何提示?
该项目是在这里如果有人想看一看:
http://aost.googlecode.com/svn/trunk/tools/tellurium-ide。
只是不要颠覆检查出并运行以下命令:
mvn install
,然后将生成的.xpi文件安装到Firefox。
之后,您可以打开Tellurium IDE Firefox插件和JavaScript调试器Firefox插件来跟踪执行情况。
对于此问题,请转到workspace.js并在findAncestor()方法的开头设置breakpointer。
约碲IDE的更多细节在这里:
http://code.google.com/p/aost/wiki/TelluriumIde080RC1
由于提前,
约翰
您确定调用了`Workspace.prototype.findAncestor`吗?也许尝试添加一些输出,证明它在之后立即被设置:`console.log('data has been set:'+ this.ancestor.data(UimConst.HEIGHT));` – clarkf 2010-12-02 20:16:43
是的。它被称为。我使用JavaScript调试器来追踪执行流程。 – 2010-12-02 20:18:09