Reputation: 365
I'm begginner in Ext JS and i want to send my Java Form to an ext js store who has a defined model : This is my Java Form :
public class Form {
private member1;
private member2;
private List<AnotherType> membersList;
//getters and setters
}
This is my store :
Ext.define('MyApp.store.Mystore', {
extend : 'Ext.data.Store',
model : 'MyApp.model.MyModel',
proxy : {
type: 'rest',
url : '/myapp/url/for/findForm',
reader: {
type: 'json'
rootProperty : 'form'
},
writer: {
type: 'json'
}
}
}
How to define MyModel for include list of members ?
And how to use this list once my store is loaded ? (it's a list to load a combox)
Thanks !
Upvotes: 1
Views: 164
Reputation: 2180
Your models could look something like this. I've used a naming pattern similar to what you used in your question.
Ext.define("MyApp.model.Form", {
extend: "Ext.data.Model",
fields: [
{name: "member1", type: "string"},
{name: "member2", type: "string"},
],
hasMany: {
model: "MyApp.model.AnotherType",
name: "membersList",
associationKey: "membersList"
}
});
Ext.define("MyApp.model.AnotherType", {
extend: "Ext.data.Model",
fields: [
{name: "value", type: "string"},
{name: "label", type: "string"},
]
});
You can create a combo box like this.
Ext.create("Ext.form.ComboBox", {
fieldLabel: "Members",
store: Ext.getStore("MyApp.store.Mystore").getAt(0).membersList(),
queryMode: "local",
displayField: "label",
valueField: "value",
renderTo: Ext.getBody()
});
Note that the above is just an example using the first MyApp.model.Form
in your store. You'll likely want to create the combo box in a more generic way, but I'm not sure of the specifics for your case.
Upvotes: 2