PDA

View Full Version : How to test Custom filtering of Model?



softball
12 Jun 2014, 6:37 PM
Dear?
In the sample from :
http://www.objis.com/formationextjs/lib/extjs-4.0.0/docs/api/Ext.data.HasManyAssociation.html

I have changed the code to fellow Associate sample?
But?how to add 2 User's data ,and product's data,then make sure I have filter by User.name='Ed'



<script type="text/jscript">
Ext.require(['Ext.grid.*', 'Ext.data.*' ]);
var uersX;
var productsX;
var store;
Ext.onReady(function(){


Ext.define('Product', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'user_id', type: 'int'},
{name: 'name', type: 'string'}
],
proxy: {type: 'ajax',
url: 'users'
},
autoLoad: true

});

Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'}
],

hasMany: {model:'Product'
,name: 'products'
,filterProperty: 'name'}
});



userX = Ext.ModelManager.create({id: 1, name: 'Ed'}, 'User');

productsX = userX.products();


productsX.add({ name: 'Another Product'});
productsX.add({ name: 'Another Product2'});


productsX.sync();

store = new User({query: 'name'}).products();
})
</script>