I’m very new to JavaScript and I need some advice on why I am getting an error message that states this.node is undefined.
What I have is a app built on ExtJs using the MVC architect. In my Controller, I have developed a layout containing a tree and a grid. In the tree, there are parent nodes that can be added by clicking a New button and its method works perfectly.
However the method that will update a record by id from my database using the same form that is used to insert a record is generating a message stating the this.node is undefined.
This is my code for the 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();
},
Replace your
handleBtnEditwith this version and copy paste your console log.Also, add the code which calls
handleBtnEdit.Update
Console log:
So, the argument passed in a button with
id= "btn-edit".thisseems to be anObjectwithid= "ProblemRequirements".Update 2
As there is no node inside
thisand theidof this doesn’t seem to be one we need, try this code: