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

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

      0  

    Default


    The link I posted is a bug report, so I guess it already got fixed (after looking at the Fixed prefix )

    Anyhow I still have one minor Problem... when Calling the load() function in my controller I somehow can't find a way to get the model data to my controller.

    The load() doesn't have a return value, so I'm struggling with getting the model instance to a variable or sth.
    If I access "this" in the success function it ofc references the model class. with app.controller.Browse.activeItem = newRecord; it doesn't work as app.controller.Browse.activeItem is not set on the load function properly.

    Any Idea? It's probably really easy, I just don't get it anymore after 14 hours programming straight.. thanks for the help...

    rho

    P.S. somebody gotta send me the address of ST dev teams office, so I can send you folks a pizza for a) awesome product b) awesome free support.. I'm not kidding -> get me the information

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

      0  

    Default


    Just for future reference, if somebody is checking this thread:
    to make all that stuff work, like the model success function access the controller functions just define the scope: this so the code looks like this:

    Code:
    app.model.Product.load(27, {
    				model: 'app.model.Product',
    				scope: this,
    				success: function (newProduct) {
    					console.log(this.getProductDisplay()); // to demonstrate controller access
    				}
    			});
    It might be trivial, but took me a bit to figure out So I thought I'll just leave this here.

  10. #9
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Answers
    28
    Vote Rating
    9
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    Yes, the fact that the model was not passed automatically when calling the load method has been fixed.

    If you want to run the callback function in the scope of the controller, you will have to set the scope in the options like you did above.

  11. #10
    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


    Quote Originally Posted by rhomb View Post
    P.S. somebody gotta send me the address of ST dev teams office, so I can send you folks a pizza for a) awesome product b) awesome free support.. I'm not kidding -> get me the information
    We're actually in a secret location away from the main HQ this month so I can't give you the address

    People do send us little treats from time to time which is very generous but totally not required, we'll try to live up to your expectations either way. That said I don't want to be rude so if you do want to send the team something you're welcome to do so - HQ is at Suite 120, 1700 Seaport Boulevard, Redwood City, CA 94063 - if you mark for my attention I'll see the team gets it
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer