gpt4 book ai didi

javascript - 未定义的函数

转载 作者:行者123 更新时间:2023-11-28 16:07:34 25 4
gpt4 key购买 nike

我对 JavaScript 很陌生,我需要一些建议来了解为什么我会收到一条错误消息,指出 this.node未定义

我拥有的是一个使用 MVC 架构师在 ExtJs 上构建的应用程序。在我的 Controller 中,我开发了一个包含树和网格的布局。在树中,可以通过单击“新建”按钮来添加父节点,并且该方法运行良好。

但是,使用与插入记录相同的形式从我的数据库中按 id 更新记录的方法会生成一条消息,说明 this.node未定义

这是我的编辑处理程序代码:

handleBtnEdit: function (btn, ev, eOpts) {
console.log(this);
var id = parseInt(this.node.get("id")), rec = this.app.getStore("ProblemRequirements").getById(id);
this.launchForm(rec);
},
handleBtnAdd: function (btn, ev, eOpts) {
var rec = Ext.create("SPOT.model.ProblemRequirement");
this.launchForm(rec);
},
handleBtnSave: function (btn, eOpts) {
var win = btn.up("window"), pnl = win.down("form"), frm = pnl.getForm(), grid = pnl.down("grid"), store = grid.getStore(), rec = frm.getRecord();
if (frm.isValid()) {
rec.set(frm.getValues());
win.setLoading("Saving, please wait...");
rec.save({
callback : function(rec, operation) {
if (operation.success) {
win.close();
this.getStore("ProblemRequirements").load();
this.playMsg("Problem requirement successfully " + (operation.action === "update" ? "updated" : "created" ) + ".");
} else {
win.setLoading(false);
Ext.Msg.alert("Error!", operation.error[0].ERROR);
}
},
scope : this
});
}
},
launchForm: function (rec) {
Ext.create("Ext.window.Window", {
buttons : [{
handler : this.handleBtnSave,
scope : this,
text : "Save"
}, {
handler : this.handleBtnCancel,
scope : this,
text : "Cancel"
}],
closable : false,
draggable : false,
iconCls : (rec.phantom ? "icon-add" : "icon-edit"),
items : [{
listeners : {
afterrender : {
fn : function(pnl, eOpts) {
pnl.getForm().loadRecord(rec);
},
scope : rec
}
},
xtype : "problemrequirementForm"
}],

modal : true,
resizable : false,
title : (rec.phantom ? "Create a New" : "Edit") + " Problem Requirement",
width : 500
}).show();
},

最佳答案

用此版本替换您的 handleBtnEdit 并复制粘贴您的控制台日志。

handleBtnEdit: function (btn, ev, eOpts) {
console.log("-- Start of handleBtnEdit --");

console.log(btn);
console.log("-- 1 --");

console.log(ev);
console.log("-- 2 --");

console.log(this);
console.log("-- 3 --");

console.log(this.getAttribute("id"));
console.log("-- 4 --");

console.log(this.node);
console.log("-- 5 --");

//var id = parseInt(this.node.get("id"));
//var rec = this.app.getStore("ProblemRequirements").getById(id);
//this.launchForm(rec);
},

此外,添加调用handleBtnEdit的代码。

更新

控制台日志:

-- Start of handleBtnEdit -- 
btn :: Object { disabled= false , iconCls= "icon-edit" , id= "btn-edit" , more...}
-- 1 --
ev :: Object { browserEvent=Event click, type= "click" , button= 0 , more...}
-- 2 --
this :: Object { application={...}, id= "ProblemRequirements" , hasListeners={...}, more...}
-- 3 --

因此,参数通过 id= "btn-edit" 传入按钮。this 似乎是一个带有 id=“ProblemRequirements”Object

更新2

由于 this 内没有节点,并且 this 的 id 似乎不是我们需要的节点,请尝试以下代码:

handleBtnEdit: function (btn, ev, eOpts) {
var id = parseInt(btn.id);
var rec = this.application.getStore("ProblemRequirements").getById(id);
this.launchForm(rec);
},

关于javascript - 未定义的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14264976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com