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

obj.get function fails if constructor is defined in ExtJs Class prototype

本文关键字:构造函数 get 失败 函数 定义 如果 ExtJs 原型 obj      更新时间:2023-09-26

我是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"));

你能帮我弄明白这是怎么回事吗


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