How can i get data from server in sencha touch - sencha-touch

I am new to sencha touch can any one help me, what is the way to get data from server. I didn't understand clearly. Please help me. In need to display the values from server to grid. I dont how to do that.Now I have added the values directly to grid store.

You should dive deeper into two aspects of Sencha Touch: models and stores. A model is simply a representation of an object. For example, you could define 'User' as a model with the fields 'id', 'username', 'email'. Stores can be seen as collections of model-objects.
The beauty of Sencha is that the models / stores can be given a proxy parameter. There are various proxies available, but you should choose the one that suits application the best. For example, the AjaxProxy sends a request to the server to load the data. Once your store is loaded (please not that AJAX calls are made asynchronous) you can populate it in for exampe a List or NestedList.
Some example code, directly taken from the docs:
Ext.regModel('User', {
fields: ['id', 'name', 'email']
});
//The Store contains the AjaxProxy as an inline configuration
var store = new Ext.data.Store({
model: 'User',
proxy: {
type: 'ajax',
url : 'users.json'
}
});
store.load();

you can use this tutorial.
it's very useful
http://programmersgoodies.com/how-to-parse-xml-response-with-sencha-touch#comment-27

Download the SDK of sencha touch2 and then you can refer example which is present in sencha sdk for using the servers. This is important to use web services for getting data from servers.
Just refer to the below link.
sencha-touch-2.0.1.1\examples\ajax

Related

Ember change normalizeResponse based on queried model

I'm using a second datastore with my Ember app, so I can communicate with a separate external API. I have no control over this API.
With a DS.JSONSerializer I can add some missing properties like id:
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
if (requestType == 'query') {
payload.forEach(function(el, index) {
payload[index].id = index
})
}
Now I can do some different tricks for each different requestType. But every response is parsed. Now sometimes a response from one request needs to be parsed differently.
So what I am trying to do is change the normalizeResponse functionality for each different request path (mapped to a fake model using pathForType in an adapter for this store). But the argument store is always the same (obviously) and the argument promaryModelClass is always "unknown mixin" - not sure if this can be any help.
How can I find what model was requested? With this information I could do a switch() in normalizeResponse.
Is there a different way to achieve my goal that does not require me to make a separate adapter for every path/model?
There are over a dozen normalize functions available. Something should work for what I am trying to achieve.
I think this is a great example of a use case of not using ember data.
Assuming that you have models A,B,C that are all working great with ember data, leave those alone.
I'd create a separate service and make raw requests to that different endpoint. So you'd replace this.store.query('thing', {args}) with a separate service that uses ember-ajax (or ember-fetch or whatever). If you need, you can use that service to hold the data that you need (Ember-data is just a service anyway) or you can create models and push them into the store manually.
Without knowing more about your exact situation, hard to give a specific code/advice, but I'd just avoid this problem and write your own custom service.
You can use primaryModelClass.modelName.

Sencha Touch: Store without proxy

I have been wandering on the internet for a basic question regarding Sencha Touch Stores.
The question is , If we don't use any proxy like WebSQL, localstorage etc for the store then where is the data stored? Or Where can we view the data?
Elaboration Of My question
I have created a store like this.
Ext.define('MyApp.store.UserPass',{
extend: 'Ext.data.Store',
config:{
model:'MyApp.model.UP',
storeId:'UserPasswords',
//no proxy
}
});
At runtime , I add some data in the store using
Ext.getStore('UserPass').add({param1 : "data1" , param2 : "data2"});
Then I binds this store to a List. Everything works fine.
But the question is where is the data stored w.r.t to storage i.e in program's memory, browser's memory, nowhere or somewhere?
May be It looks like a silly question, but the answer of it would help me in understanding a lot of related concepts.
If you don't specify a proxy for your store, the proxy will default to Ext.data.proxy.Memory. Take a look at the code of the applyProxy method of Ext.data.Store. So there will never be a store without a proxy.

In Dojo 1.7+, FilteringSelect appear to no longer workwith ItemFileReadStore

I am upgrading an application from dojo 1.5 to 1.7. This application has several FilteringSelects that are backed by ItemFileReadStores. E.g.,
this.docTypeSel = this.adopt(dijit.form.FilteringSelect, {
name: "docType",
autoComplete: true
}, document.createElement("select"));
this.docTypeSel.placeAt(this.formNode);
var url = dojo.moduleUrl("imed", "DocumentTypes.txt");
this.documentTypeStore = new dojo.data.ItemFileReadStore({ url: url, urlPreventCache: "true" });
this.docTypeSel.store = this.documentTypeStore;
In 1.7, calls to this.docTypeSel.set('value',foo) fail as they try to call this.store.get(value). My understanding is that this is the new dojo/store API. Is there some sort of adapter between the old dojo.data API's and the new dojo/store API? If not, what is the recommended replacement for ItemFileReadStore. dojo/store/Memory seems close, but it does not appear to have a way pull the data from an url.
Have you looked at using the dojo/store/DataStore? I haven't used it personally but it appears to be what you want to use since the dijit/form/FilteringSelect is looks for stores using the dojo/store API.
On the other hand the dijit/form/Select expects a dojo/data implementation. If you had a dojo/store implementation you wanted to use with dijit/form/Select you would use dojo/data/ObjectStore.

store.loadData not defined. How to load data into store Sencha Architect

In the past, I created my stores using Ext.create('Ext.data.Store', ...
and when I wanted to load data the was contained in a JSON loaded object, all I needed to do was MyStore.loadData(myDataObj);
This does not work with the stores you define in Sencha Architect, you get Not defined error for loadData.
I have a custom Ext.Ajax routine I use to get the data that does not lend itself to being defined in a stores proxy. My data is in the proper JSON format, but I have had no luck finding a way to force load data into a store without using a store proxy.
I was able to get MyStore.add({--json string ...}) to work, but this only adds a single record.
Why is store.loadData() not suppored ??? What can I use instead???
use store.setData assuming you are using a Touch project.
I have read the Sencha API docs. The issue here is that the Store.loadData does not appear to be valid (ie Un-defined) when referenced in a user defined function in Sencha Architect. I have not been able to find a way to take a variable that has a valid JSON object and load it into s store. The only method I believe would work is if I created the stores in a function, but that would defeat the awesome UI the architect provides.

Extjs 4 data store and php

I wanna know if it's possible to call php api like in extjs 3.x.x.
Let me explain, I have a store and I want to get data from php :
Ext.define('KY.store.watcherStore',{
extend: 'Ext.data.Store',
model: 'KY.model.WatcherModel',
proxy: {
type: 'ajax',
url : '/admin/rest/ksThresholdWatcher/loadAllRef',
//reader: {
// type: 'json'
//},
}
});
The url param calls ksThresholdWatcher.php method loadAllRef (I have a php rest api);
but it never calls my php script. I'm stuck, I don't now how to do, all examples I see set url param like this url:'myPHP.php'.
How can I make it work my way ?
You need to specify that the your proxy is type: 'rest' in the config. Here is an example the restful way. This also has some good pointers on proxy usage.
You can use the api proxy config item in 4.x.x to specify different sources for the different request operations (CREATE, UPDATE, DESTROY, READ).