Tom
Tom

Reputation: 16246

Sencha ExtJs calling function with namespace prefix?

I have two models and a load success callback function, like this:

Ext.define('Desktop.model.User', {
    extend: 'Ext.data.Model',
    hasMany: ['Desktop.model.Module'],
    //......
});
Ext.define('Desktop.model.Module', {
    extend: 'Ext.data.Model',
    belongsTo: 'Desktop.model.User'
    //......
});

And

Desktop.model.User.load('', {
    success : function(user,options) {
        user.desktop.model.modules().each(function(module) {
            //**** ERROR HERE ****
            //.......
        }
    }
});

At debug breakpoint, I can see there is a desktop.model.modules() function in the user object auto generated by the store, but I am not sure about the correct syntax to call it. If I call it directly like above, error will occure saying desktop.model is undefined, treating it as a property instead of part of the namespace of the Module model.

Am I taking the wrong approach with namespace? Or how do I do call the function with that namespace correctly?

Upvotes: 0

Views: 475

Answers (1)

Evan Trimboli
Evan Trimboli

Reputation: 30082

Specify the name property on the hasMany:

Ext.define('Desktop.model.User', {
    extend: 'Ext.data.Model',
    hasMany: {
        model: 'Desktop.model.Module',
        name: 'modules'
    }
});
// Later
user.modules().each();

Upvotes: 1

Related Questions