问题是这样的,下面的代码我在"红1"处alert是可以弹出预想的内容,可是,在"红2"处却跟我说undefined,有人知道为什么吗?
详细情形: 页面初始化的时候会执行enableItemEditor 方法,这时会弹出红1,可是,当点击节点(触发setOnClickHandler方法)时,却提示undefined。
[code="java"]
dhtmlXTreeObject.prototype.enableItemEditor = function (mode) {
this._eItEd = convertStringToBoolean(mode);
alert(this._stopEditItem);// 红1
if (!this._eItEdFlag) {
this._edn_click_IE = true;
this._edn_dblclick = true;
this._ie_aFunc = this.aFunc;
this._ie_dblclickFuncHandler = this.dblclickFuncHandler;
this.setOnDblClickHandler(function (a, b) {
if (this._edn_dblclick) {
this._editItem(a, b);
}
return true;
});
this.setOnClickHandler(function (a, b) {
alert(this._stopEditItem);//红2
this._stopEditItem(a, b);
if ((this.ed_hist_clcik == a) && (this._edn_click_IE)) {
this._editItem(a, b);
}
this.ed_hist_clcik = a;
return true;
});
this._eItEdFlag = true;
}
};
dhtmlXTreeObject.prototype._stopEditItem = function (id, tree) {
alert(id);
this._stopEdit(id);
};
[/code]
这段js代码怎么回事?高手帮我看下
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- wanghaolovezlq 2009-08-19 15:06关注
应该修改成这样
[code="java"]
dhtmlXTreeObject.prototype.enableItemEditor = function (mode) {
this._eItEd = convertStringToBoolean(mode);
alert(this._stopEditItem);// 红1
if (!this._eItEdFlag) {
this._edn_click_IE = true;
this._edn_dblclick = true;
this._ie_aFunc = this.aFunc;
this._ie_dblclickFuncHandler = this.dblclickFuncHandler;
this.setOnDblClickHandler(function (a, b) {
if (this._edn_dblclick) {
this._editItem(a, b);
}
return true;
});
//用闭包来解决this的问题
var that = this;
this.setOnClickHandler(function (a, b) {
alert(that._stopEditItem);//红2
that._stopEditItem(a, b);
if ((that.ed_hist_clcik == a) && (that._edn_click_IE)) {
that._editItem(a, b);
}
that.ed_hist_clcik = a;
return true;
});
that._eItEdFlag = true;
}
};
dhtmlXTreeObject.prototype._stopEditItem = function (id, tree) {
alert(id);
this._stopEdit(id);
};
[/code]本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
- ¥200 uniapp长期运行卡死问题解决
- ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
- ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
- ¥15 乘性高斯噪声在深度学习网络中的应用
- ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
- ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
- ¥15 C++ 头文件/宏冲突问题解决
- ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
- ¥50 安卓adb backup备份子用户应用数据失败