Results 1 to 2 of 2

Thread: Creating a new load() method on a model

  1. #1
    Sencha Premium Member
    Join Date
    Feb 2016
    Posts
    51
    Answers
    1
    Vote Rating
    13
      0  

    Default Creating a new load() method on a model

    Hi,

    I'm quite new to Ext and JS, so may have this completely wrong, but I'm looking to have two methods to read data into a model - a standard read method which takes the ID field and a 2nd method that reads default values from a second url based on a DefaultID (that isn't stored in the model).

    I'm trying to define it in the model like this:

    Code:
    Ext.define('App.MyModel', {
    	extend: 'Ext.data.Model',
        ...
    	proxy:{
    		type: 'ajax',
    		reader: {
    			type: 'xml',
    			root: 'data'
    		},
    		writer: {
    			type: 'xml'
    		},
    		api: {
    			create: '/bti/te_web_services?action=CREATE_TRANSPORT'
    			// read:
    			// update:
    			// destroy:
    		}
    	},
    	defaultProxy:{
    		type: 'ajax',
    		reader: {
    			idProperty: 'TASK',
    			type: 'xml',
    			root: 'data'
    		},
    		extraParams: {
    			TASK : ''
    		},
    		url: '/bti/te_web_services?action=GETTRANSPORTDEFAULTS'
    
    
    	},
    	loadDefaults: function(taskId) {
    		// use the defaultProxy and revert back to the original after
    		var oldProxy = this.getProxy();
    		var oldIdProperty = this.idProperty;
    		try {
    //			this.idProperty = 'TASK'
    			console.log(this);
    			this.setProxy(this.defaultProxy);
    			this.defaultProxy.
    			this.load(taskId);
    		}
    		finally {
    			this.setProxy(oldProxy);
    			this.idProperty = oldIdProperty;
    			}
    	}
    });
    This would be called like this:


    Code:
    		var transportRecord = Ext.create('App.MyModel', {
    			TASK : this.getCurrentTaskId()
    		});
    		transportRecord.loadDefaults(transportRecord.data.TASK, {
    			success: function() {
    				newTransportEntryForm.getForm().loadRecord(transportRecord);
    				newTransportEntryForm.show();
    			}
    		});
    However I'm getting the code faulting complaining that this.load is not a function (though code completion in Chrome debugger seems to find save() OK?

    Can I get a pointer into what I'm doing wrong? Also, is there a neater way to have a fifth operation in addition to the normal CRUD to avoid switching to a 2nd proxy which feels a bit hacky?

  2. #2
    Sencha Premium Member
    Join Date
    Feb 2016
    Posts
    51
    Answers
    1
    Vote Rating
    13
      0  

    Default

    OK - I've realised I'm getting confused with static methods.It appears I can call my own 'CRUD' method by adding an extra string to the 'api' definition and then using that in the 'action' field of the config object passed into load().Unfortunately for me, I've just discovered that the API that I'm using doesn't map the fields from the two calls so I need a whole new model anyway :-(

Similar Threads

  1. Loading data via a Model.. model has no method load()
    By rhomb in forum Sencha Touch 2.x: Q&A
    Replies: 10
    Last Post: 12 Sep 2013, 11:40 AM
  2. model.load Method
    By drgaryholland in forum Ext: Q&A
    Replies: 0
    Last Post: 13 Jan 2013, 11:16 AM
  3. Creating a copy of a Store/Model doesn't load the data
    By softwarezman in forum Ext: Discussion
    Replies: 1
    Last Post: 30 Jul 2011, 5:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •