Extjs4-在模型上定义方法

Extjs4-在模型上定义方法,extjs4,Extjs4,根据,我应该能够在模型上定义函数,然后在该模型的实例上调用该函数 至少在我从代理加载模型的情况下,它不起作用 我的模型: Ext.define('MyApp.model.Detail', { extend: 'Ext.data.Model', fields: [ 'someField', 'anotherField', ], someFunction: function() { //do something

根据,我应该能够在模型上定义函数,然后在该模型的实例上调用该函数

至少在我从代理加载模型的情况下,它不起作用

我的模型:

Ext.define('MyApp.model.Detail', {
    extend: 'Ext.data.Model',
    fields: [
        'someField',
        'anotherField',
    ],

    someFunction: function() {
            //do something
    },

    proxy: {
        type: 'ajax',
        url: 'http://example.com/details',
        reader: {
            type: 'json',
            root: 'data',
            totalProperty: 'total',
            successProperty: 'success',
        }
    },
});
商店:

Ext.define('MyApp.store.DetailStore', {
    extend: 'Ext.data.Store',
    storeId: 'detailStore',
    model: 'MyApp.model.Detail',
});
控制器:

Ext.define('MyApp.controller.appController', {
    extend: 'Ext.app.Controller',
    init: function() {
        this.getDetailStoreStore().addListener('load', this.newDetails, this);
    },

    stores: ['DetailStore'],

    models: ['Detail'],

    views : ['DetailView], //exists, not copied into question

    newDetails: function(store, records) {
        var details = records[0].data;
        details.someFunction();  // Uncaught TypeError: Object #<Object> has no method 'someFunction'
    }
});
Ext.define('MyApp.controller.appController'{
扩展:“Ext.app.Controller”,
init:function(){
this.getDetailStoreStore().addListener('load',this.newDetails,this);
},
门店:['DetailStore'],
型号:[“详细信息”],
视图:['DetailView],//存在,未复制成问题
新详细信息:功能(存储、记录){
var details=记录[0]。数据;
details.someFunction();//未捕获类型错误:对象#没有方法“someFunction”
}
});
调用data.someFunction()时,newDetails函数中发生错误


我是否有错误的预期?

该函数存在于模型上,因此您可以调用:

records[0].someFunction();

非常感谢您的快速回复,这完全正确。:)另一个细节是,在someFunction中,您需要调用this.data来获取实际填充的数据字段。再次感谢!您应该真正使用这个.get()而不是访问原始数据属性。