如果构造函数在ExtJs类原型中定义,则obj.get函数失败

时间:2014-06-13 10:07:45

标签: javascript extjs extjs4

我是ExtJs世界的新手,并开始使用ExtJs 4并使用“学习extJs 4”这本书

这是我正在玩的代码片段


Ext.define("MyApp.Category",{
height : 40,
extend : "Ext.data.Model",
fields : [ 
    "id",
    "name",
    "description"
],

constructor : function(config){
    console.log("Config Dump \n");
    console.dir(this);
    //Ext.apply(this, config);
}



});


var category = Ext.create("MyApp.Category",{
id : 1,
name : "Entertainment",
description : "Expenses to have some fun"
});

console.log("this is after instantiation..");
console.debug(category);

console.log(category.get("name"));  
// above line fails gives error - Uncaught TypeError:    Cannot read property 'name' of undefined 
// but if we remove construction defination from class prototype , .get function works very well
console.log(category.get("description"));

请你帮我理解这里的事情


1 个答案:

答案 0 :(得分:0)

您必须调用父构造函数。将this.callParent(arguments)添加到构造函数覆盖。