私はJavaScriptを初めて使用するので、「」というエラーメッセージが表示される理由についてアドバイスが必要this.node
ですundefined
。
私が持っているのはExtJs
、MVCアーキテクトを使用して構築されたアプリです。私のコントローラーでは、ツリーとグリッドを含むレイアウトを開発しました。ツリーには、[新規]ボタンをクリックして追加できる親ノードがあり、そのメソッドは完全に機能します。
ただし、レコードの挿入に使用されるのと同じフォームを使用してデータベースからレコードを更新するメソッドは、 isid
を示すメッセージを生成しています。this.node
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();
},