Sencha Touch query - sencha-touch

how I add querystring in sencha touch?
?name=jake as
localhost/JSONDemo/XMLToJson.aspx?name=jake
My code is
Ext.regStore('NewsItems', {
model: 'NewsItem',
proxy: {
type: 'ajax',
url: 'XMLToJson.aspx',
reader: {
type: 'json',
root: 'liste.dokuman'
}
},
autoLoad: true
});

You can pass additional parameters using the extraParams property available with your proxy object. Here is an example:
Ext.regStore('NewsItems', {
model: 'NewsItem',
proxy: {
type: 'ajax',
url: 'XMLToJson.aspx',
extraParams: {
name: 'jack'
},
reader: {
type: 'json',
root: 'liste.dokuman'
}
},
autoLoad: true
});

Related

Sencha Touch 2 custom rest proxy url

I have a rest api and for user authentication, the rest url is:
https://api.abc.com/user/{username}/{password}. So I need to set two parameters for the rest proxy. Can any one please help me?
Here is my User model:
Ext.define('NCAPP.model.User', {
extend:'Ext.data.Model',
config:{
fields:[
{ name:'id', type: 'int'},
{ name: 'username', type: 'string'},
{ name: 'netshop_id', type:'int'},
{ name: 'firstname', type: 'string'},
{ name: 'lastname', type: 'string'},
{ name: 'address', type: 'string'},
{ name:'password', type:'string'},
],
proxy: {
type:'rest',
url:https://api.abc.com/user/',
noCache: false,
reader: {
type:'json',
rootProperty:'user'
}
}
}
});
And here is my LoginController on loginbuttion tap function:
onLoginButtonTap:function(){
var values=this.getLoginForm().getValues();
Ext.ModelMgr.getModel('NCAPP.model.User').load(values.username,{
success: function(user){
if(user==null)
{
Ext.Msg.alert('NCAPP',"Invalid username or password!");
}
else
{
Ext.Msg.alert('NCAPP','Welcome! '+user.get('username'));
//do after login implementation
}
},
failure: function(user){
console.log("Uff, Something went worng!");
}
});
},
In the following line, i want to pass user name and password:
Ext.ModelMgr.getModel('NCAPP.model.User').load(values.username, values.password, {.....
Can anyone help me achieving this goal?
You can use the method "setProxy" to add dynamically a proxy to your model/Store.
var values = this.getLoginForm().getValues();
YOURMODEL.setProxy({
proxy: {
type: 'rest',
url: 'https://api.abc.com/user/'+ values.username +'/'+ values.password,
noCache: false,
reader: {
type: 'json',
rootProperty: 'user'
}
}
});

Sencha Touch 2 - Add model to store only once

I have a store which gets its value through a proxy to the server. But I want to hard code one country (null country) which should be appended to the store around in the sencha code
I tried a naive
data: [
{
id: '999',
countryCode: 'NullCountry',
countryName: 'Null (+nothing)',
countryPhoneCode: null
}
]
But it doesnt work (it was just an attempt). How can I do this?
Ext.define('Sencha.store.CountryStore', {
extend: 'Ext.data.Store',
config: {
id : 'CountryStore',
model:'Sencha.model.user.Country',
proxy: {
type: 'rest',
url : '/countries',
headers: {
'Content-Type': 'application/json',
'Accept' : 'application/json'
},
reader: {
type: 'json',
rootProperty: 'countries'
}
},
autoLoad: true,
data: [
{
id: '999',
countryCode: 'NullCountry',
countryName: 'Null (+nothing)',
countryPhoneCode: null
}
]
}
});
You could listen to the store load event and then add the new record then:
Ext.define('Sencha.store.CountryStore', {
extend: 'Ext.data.Store',
config: {
id : 'CountryStore',
model:'Sencha.model.user.Country',
proxy: {
type: 'rest',
url : '/countries',
headers: {
'Content-Type': 'application/json',
'Accept' : 'application/json'
},
reader: {
type: 'json',
rootProperty: 'countries'
}
},
autoLoad: true,
listeners: {
load: function(me) {
me.add({
id: '999',
countryCode: 'NullCountry',
countryName: 'Null (+nothing)',
countryPhoneCode: null
});
}
}
}
});

Sencha Touch 2 Store TypeError

I'm following the video on the Sencha website, for creating my first application.
This is the video I'm following: Video
This is the code I'm using for the Blog tab:
Ext.define('GS.view.Blog',{
extend: 'Ext.navigation.View',
xtype: 'blogpanel',
requires: [
'Ext.dataview.List',
'Ext.data.proxy.JsonP'
],
config: {
title: 'Blog',
iconCls: 'star',
items: {
xtype: 'list',
itemTpl: '{title}',
store: {
autoLoad: true,
fields: ['title', 'author', 'content'],
root: {
leaf: false
},
proxy: {
type: 'jsonp',
url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog',
reader: {
type: 'json',
rootProperty: 'responseData.feed.entries'
}
}
}
}
}
});
In the Safari Console, it is giving me the following error on StoreManager.js:97:
TypeError: 'undefined' is not a valid argument for 'instanceof' (evaluating 'store instanceof Ext.data.Store')
What am I doing wrong?
add this code at line store:
store: new Ext.create('Ext.data.Store',{
autoLoad: true,
fields: ['title', 'author', 'content'],
root: {
leaf: false
},
proxy: {
type: 'jsonp',
url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog',
reader: {
type: 'json',
rootProperty: 'responseData.feed.entries'
}
}
})

Variables between List

My problem is... I have a list who is completed by a store and this store comes from a proxy (json). When i clik in a item of the list i need a detail information, and this detail information comes from anothe json.
For example:
ArtistList and ArtistDetail
When i click in an item of artistList i need a call to
http://localhost/json-detail/45
if i click in another item...
http://localhost/json-detail/50 etc...
My problem is that i can't send the parameter to the other view... or maybe the error is in my concept of lists... :S
This is my list view:
var listaArtistas = {
xtype: 'list',
title: 'Artistas',
height: 240,
store: {
autoLoad: true,
fields: ['node'],
proxy: {
type: 'ajax',
url: 'http://localhost/json-artistas',
reader: {
type: 'json',
rootProperty: 'nodes'
}
}
},
listeners: {
itemtap: function(lista,index,target,record,e,eOpts)
{
var artistDetail = new Ext.create('app.view.ArtistDetail');
artistDetail.setArtistID('45');
panelHomeNav.push(artistDetail);
}
},
itemTpl: tpl
};
This is my detail:
Ext.define('app.view.ArtistDetail',{
extend: 'Ext.Panel',
xtype: 'artistdetail',
style: "background-image:url('/resources/images/fondoartista.png');",
config:{
title: 'Artistas',
iconCls: 'star',
ArtistID: '',
items:
{
title: 'Artistas',
items: [artistDetailPanelContenedor]
}
}});
And need something like this
var listaEspectaculo = {
xtype: 'list',
title: 'Artistas',
store:
{
autoLoad: true,
fields: ['node'],
proxy: {
type: 'ajax',
url: 'http://localhost/json-artistasdetail/'+getArtistID, <<<<<<<<<<------ PROBLEM
reader: {
type: 'json',
rootProperty: 'nodes'
}
}
},
listeners: {
itemtap: function(lista,index,target,record,e,eOpts)
{
var eventDetail = new Ext.create('app.view.EventDetail');
panelHomeNav.push(eventDetail);
}
},
itemTpl: tplEspectaculo
};
THx for help !!!
Maybe this could help:
How to pass value from controller to data store in sencha touch
handler: function () {
Ext.dispatch({
controller: MyApp.controllers.controller,
action: 'myActionOnController',
id: e.get{'id'}
});
}
You can call ext.dispatch from your "itemtap", then in the controller you can call a new view with you parameters, remember use something like this:
myActionOnController: function (options) {
var city = options.id; //if you want to use your parameters
var newView = Ext.create('MyApp.view.viewOfSomething');
this.getMain().push(newView);
},

Ext.Ajax.request Sencha Touch

I want to make a simple request like Ext.Ajax.request and display it in a list. But it does not work.
I have a URL like this
http://server/GetContacts.aspx?CustAccount=10019
Can someone tell me exactly how it works and what I should consider?
This is an example of what I get back.
{
"HasError": false,
"ErrorString": "",
"Data": [
{"ContactPersonId":"","Name":"","FirstName":"","MiddleName":"","LastName":"","Phone":"","CellularPhone":"","Telefax":"","Email":"","Url":"","Address":"","ZipCode":"","City":"","Street":"","Country":"","Function":""}
]
}
Ext.regModel('kunden', {
idProperty: 'id',
fields: [
{ name: 'ContactPersonId', type: 'string' },
.
.
.
{ name: 'Function', type: 'string' }
]
});
Ext.regStore('kundenStore', {
model: 'kunden',
sorters: [{
property: 'LastName'
}],
proxy: {
type: 'ajax',
url: 'http://server/GetContacts.aspx?CustAccount=10019'
},
reader: {
type: 'json',
root: 'Data'
}
});
NotesApp.views.kundenList = new Ext.List({
id: 'kundenList',
store: 'kundenStore',
grouped: true,
indexBar : true,
itemTpl: '<div class="list-item-title">{firstname} {lastname}</div>' +'<div class="list-item-narrative">{email}</div>',
listeners: {}
}
});
It can be so easily XP