Hybrid View

  1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    26
    Answers
    1
    Vote Rating
    0
    rhomb is on a distinguished road

      0  

    Default Answered: Loading data via a Model.. model has no method load()

    Answered: Loading data via a Model.. model has no method load()


    Hello,


    usecase: I want to create a Model, which is already defined, in a controller, and somehow I can't create it / load data.


    Product.js:
    Code:
     Ext.define('app.model.Product', {  
    	extend: 'Ext.data.Model',  
    	config: {  
    		idProperty: 'id',  
    		fields: ['id', 'name', 'price', 'description', 'imageurl', 'super_attribute', 'additional_attributes'],
    		proxy: {  
    			type: 'ajax',  
    			url: '/product/view',  
    			reader: {  
    				type: 'json',  
    			}  
    		}  
    	}
    });
    and in the Controller I call
    Code:
        product = Ext.create('app.model.Product');  
        product.load(27, {
            success: function (newModel) {
               console.log('success');
            }
    });
    If I try to initialize the model like that:
    var product = Ext.ModelManager.getModel('app.model.Product');
    doesn't change anything

    Error Message in console: Object [object Object] has no method 'load'
    in PR3 this wasn't that much of a Problem

    Any Idea what it could be?

  2. You're calling .load on an instance but it's a static function - do it like this instead:

    Code:
    app.model.Product.load(123, {
        success: function(product) {
            console.log('success');
        }
    });

  3. #2
    Sencha User
    Join Date
    Dec 2011
    Posts
    26
    Answers
    1
    Vote Rating
    0
    rhomb is on a distinguished road

      0  

    Default


    delete pls - was an unrelated post

    problem above still exists though

  4. #3
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Answers
    29
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    You're calling .load on an instance but it's a static function - do it like this instead:

    Code:
    app.model.Product.load(123, {
        success: function(product) {
            console.log('success');
        }
    });
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  5. #4
    Sencha User
    Join Date
    Dec 2011
    Posts
    26
    Answers
    1
    Vote Rating
    0
    rhomb is on a distinguished road

      0  

    Default


    Thanks edspencer.. good to know! but unfortunately it still doesn't work.. different error though:

    Uncaught Error: [ERROR][Ext.data.Operation#setModel] An Operation needs to have a model defined.

    Code:
    Code:
    app.model.Product.load(27, {
    				success: function (newProduct) {
    					console.log(newProduct);
    				}
    			});
    Model:
    Code:
    Ext.define('app.model.Product', {	extend: 'Ext.data.Model',
    	config: {
    		idProperty: 'id',
    		fields: ['id', 'name', 'price', 'description', 'imageurl', 'super_attribute', 'additional_attributes'],
    		proxy: {
    			type: 'ajax',
    			url: '/product/view',
    			reader: {
    				type: 'json',
    			}
    		}
    	},
    });
    Any Idea? If you need any other code snippets, just let me know.

    Thanks
    rhomb

  6. #5
    Sencha User
    Join Date
    Dec 2011
    Posts
    26
    Answers
    1
    Vote Rating
    0
    rhomb is on a distinguished road

      0  

    Default


    Found the Solution:

    http://www.sencha.com/forum/showthread.php?176411-PR4-Model.load()-broken

    N
    ow the call looks like this:
    Code:
    app.model.Product.load(27, {
    				model: 'app.model.Product',
    				success: function (newProduct) {
    					console.log(newProduct);
    				}
    			});

  7. #6
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Answers
    29
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    That looks like a bug... I'll send Tommy here to confirm
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer