I am storing the JSON format in to Code.js of store folder.
'store' folder --> Code.js
Ext.define('LoginPage.store.Code', {
extend: 'Ext.data.Store',
model: 'LoginPage.model.Code',
autoLoad: true,
proxy: {
type: 'ajax',
api: {
read: 'data/loginResponse.json',
update: 'data/checkCredentials.json' //contains: {"success": true}
},
reader: {
type: 'json',
root: 'login',
successProperty: 'success'
}
}
});
'model' folder --> Code.js
Ext.define('LoginPage.model.Code', {
extend: 'Ext.data.Model',
fields: [
{name: 'username', type: 'string'},
{name: 'password', type: 'string'}
]
});
Now how to declare the variable of the store in Code.js of controller folder?
My JSON format is as shown below which is in correct format:
loginResponse.json
{
"login": [
{
"username": "venkat",
"password": "123"
},
{
"username": "admin",
"password": "345"
},
{
"username": "sam",
"password": "234"
},
{
"username": "paul",
"password": "456"
}
]
}
I tried :
var store = Ext.create('LoginPage.store.Code');
//showing no errors and also I can't see any items in it
//when checked through Chrome console.
The chrome console shows the following message when I keep the created store variable in console.log(store);
EDIT: The following function is always returning false even if the credentials are correct
checkJson: function(username, password){
var store = Ext.create('LoginPage.store.Code');
var matched = store.query('username', username);
//console.log(matched);
if(matched.length && matched[0].get('password') === password) {
return true;
}
else{
return false;
}
}
matched variable message in Chrome console. (username = "venkat", password = "123")