我对 JavaScript 非常陌生,我需要一些建议来说明为什么我会收到一条错误消息,this.node
即undefined
.
我拥有的是一个ExtJs
使用 MVC 架构师构建的应用程序。在我的控制器中,我开发了一个包含树和网格的布局。在树中,可以通过单击“新建”按钮添加父节点,并且其方法可以完美运行。
但是,id
使用用于插入记录的相同表单从我的数据库更新记录的方法正在生成一条消息,说明this.node
is undefined
.
这是我的代码Edit handler
:
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();
},