View Full Version : Model class use Proxy Sample

22 May 2014, 7:58 PM
Model class use Proxy Sample
As the sample of Module useing Proxy?
In Console log
Q1.I can see "Saved Ed! His ID is 2 "
it seem to save the "Ed Spencer" to the fisrt recors of json file"users" ?
but I try to use userStore.getCount()?it still show 3 ? not 4 (if it has been added)?


GET 404 (Not Found)

I use Extjs.4.2.1


Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'age'],
proxy: {
type: 'rest',
url : 'users3.json',
reader: {
type: 'json',
root: 'users'

var userStore;
Ext.onReady(function() {
// Uses the User Model's Proxy
userStore = Ext.create('Ext.data.Store', {
model: 'User',
autoLoad: true

// Gives us a reference to the User class
var User = Ext.ModelMgr.getModel('User');

var ed = Ext.create('User', {
name: 'Ed Spencer',
age : 25

// We can save Ed directly without having to add him to a Store first because we
// configured a RestProxy this will automatically send a POST request to the url data/users
success: function(ed) {
console.log("Saved Ed! His ID is "+ ed.getId());

// Load User 1 and do something with it (performs a GET request to /users/1)
User.load(1, {
success: function(user) {
console.log("Loaded user 1: " + user.get('name'));


--------------users3.json is
success: true,
usersData: [
{id: 2, name: 'Tommy',age:40},
{id: 3, name: 'Ed',age:30},
{id: 4, name: 'Ed X',age:45}

24 May 2014, 7:33 AM
If you type in your URL in question 2 in a browser, do you get a result? what if you remove the _dc=_dc=1400817338870 from the URL

in your proxy:

proxy : {
type : 'ajax',
noCache : false, // remove param "_dc"

Is the record save to your table?, or just added to your store I see you are using a static JSON file, so I suspect you have just added it to your store and the result is based on your 3 static records in your JSON file.

25 May 2014, 4:54 PM
if i type the url in browser as:

is show 404
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

if i type the url in browser as:

i still show the same 404 message.

if i change
proxy: {
type: 'rest',
url : 'users3.json',
as ==>
proxy: {
type : 'ajax',
noCache : false, // remove param "_dc"
url : 'users3.json',

the it show ok as:
?Loaded user 1: Ed ?
no moore err message ,
why not rest ,and use ajax?

but, I still get userStore.getCount(); ==>3 ,not 4
because I am just start to learn Extjs ?
so i doen't know how to add it to db table,
I just learn form sample to try it.
So,the result may be as you said,is based on your 3 static records in your JSON file?

25 May 2014, 5:04 PM
You can still use rest, that was a cut/paste from code .. not important.

If you get a 404 from your URL, you need to find out why. Do you want the id? You can use 'appendId: false' in your proxy to remove that as well.

25 May 2014, 6:06 PM
Dear scottmartin?
I had try use appendId: false, it work.

UserMRef.load(3, {
success: function(userX) {
console.log("Loaded user 1: " + userX.get('name'));

no matter i change the number of load, it still load fist record.?
Is't will not load diffent record?

and ? I see the doc:

user.set('name','Khan Noonien Singh');

user.save();//PUT /users/123

user.save call it's self again?

Does the "Load" not load the data by id ?
LOAD(3) -->load data from id=3
LOAD(5) -->load data from id=5

25 May 2014, 6:30 PM
You URL references a file: url : 'users3.json',

Are you using a database in your real app, as you cannot modify a JSON file directly. It will not change.


25 May 2014, 7:03 PM
Dear Scott?
I does not database, just use xx.json file to test.
So... it will not work with add/update/del motion? !=.=

Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'email'],

proxy: {
type: 'rest',
url : '/users'
the url:'/users' ,is not file?

by the way,

UserMRef.load(3, ...)

is't not load(number,...) , the lumber is id?