Can some one tell me how to pass data from controller to a data store in sencha touch.
有人可以告诉我如何在sencha touch中将数据从控制器传递到数据存储。
view code
查看代码
var select = new Ext.form.Select({
id:'selectCity',
store: parking.stores.city,
displayField: 'Name',
valueField: 'Name',
placeHolder: 'Choose City',
cls:'select'
});
var citySearchButton = new Ext.Button({
cls: 'citySearch',
text: 'Search',
handler: function () {
Ext.dispatch({
controller: parking.controllers.controller,
action: 'showMapBasedOnCity',
id: Ext.getCmp('selectCity').getValue()
});
}
});
from my view i am able to pass the value to the controller.
从我的角度来看,我能够将值传递给控制器。
showMapBasedOnCity: function (options) {
var city = options.id;
//var data = parking.stores.parkingFacilityByCity.setId(city);
// parking.views.map.addMap(city);
parking.views.viewport.setActiveItem(
parking.views.map, options.animation
);
},
The problem is how to pass the value from here to the data store : I need the parameter from controller (the city value) to pass to my jsonp query to get the desired result back).
问题是如何将值从这里传递到数据存储:我需要来自控制器的参数(城市值)传递给我的jsonp查询以获得所需的结果)。
parking.stores.parkingFacilityByCity = new Ext.data.Store({
model: 'PF',
proxy: Ext.util.JSONP.request({
url: 'http://parking.511.org/index/M_GetParkingFacilityByCity',
callbackKey: 'callback',
parmas: { city: },
scope: this,
callback: function (data) {
var list = data.Root;
parking.stores.parkingFacilityByCity.loadData(data.Root);
}
})
});
Any help would be greatly appreciated.
任何帮助将不胜感激。
Thanks, Pawan
谢谢,Pawan
1 个解决方案
#1
1
In my Form on button click i get the value from and pass it on to the dispatch method. In the dispatch method i call the controller.
在我的表单按钮上单击我从中获取值并将其传递给调度方法。在调度方法中,我调用控制器。
var select = new Ext.form.Select({
id:'selectCity',
store: parking.stores.city,
displayField: 'Name',
valueField: 'Name',
placeHolder: 'Choose City',
cls:'select'
});
var citySearchButton = new Ext.Button({
cls: 'citySearch',
text: 'Search',
handler: function () {
Ext.dispatch({
controller: parking.controllers.controller,
action: 'showMapBasedOnCity',
id: Ext.getCmp('selectCity').getValue()
});
}
});
In the controller i call the method get parking facility by city which get the new data into the store.
在控制器中,我按城市调用方法获取停车设施,将新数据输入商店。
showMapBasedOnCity: function (options) {
var city = options.id;
getParkingFacilityByCity(city);
// parking.views.map.addMap();
parking.views.viewport.setActiveItem(
parking.views.map, options.animation
);
Data.js file
Data.js文件
parking.stores.parkingFacilityByCity = new Ext.data.Store({
model: 'PF',
autoload: true
});
var getParkingFacilityByCity = function (cityName) {
Ext.util.JSONP.request({
url: 'http://parking.511.org/index/M_GetParkingFacilityByCity',
callbackKey: 'callback',
params: { city: cityName },
callback: function (data) {
parking.stores.parkingFacilityByCity.loadData(data.Root);
}
});
};
Hope this helps some one. There may be other methods too. But this is the one which worked for me pretty well.
希望这对某人有所帮助。也可能有其他方法。但这对我来说非常有用。
#1
1
In my Form on button click i get the value from and pass it on to the dispatch method. In the dispatch method i call the controller.
在我的表单按钮上单击我从中获取值并将其传递给调度方法。在调度方法中,我调用控制器。
var select = new Ext.form.Select({
id:'selectCity',
store: parking.stores.city,
displayField: 'Name',
valueField: 'Name',
placeHolder: 'Choose City',
cls:'select'
});
var citySearchButton = new Ext.Button({
cls: 'citySearch',
text: 'Search',
handler: function () {
Ext.dispatch({
controller: parking.controllers.controller,
action: 'showMapBasedOnCity',
id: Ext.getCmp('selectCity').getValue()
});
}
});
In the controller i call the method get parking facility by city which get the new data into the store.
在控制器中,我按城市调用方法获取停车设施,将新数据输入商店。
showMapBasedOnCity: function (options) {
var city = options.id;
getParkingFacilityByCity(city);
// parking.views.map.addMap();
parking.views.viewport.setActiveItem(
parking.views.map, options.animation
);
Data.js file
Data.js文件
parking.stores.parkingFacilityByCity = new Ext.data.Store({
model: 'PF',
autoload: true
});
var getParkingFacilityByCity = function (cityName) {
Ext.util.JSONP.request({
url: 'http://parking.511.org/index/M_GetParkingFacilityByCity',
callbackKey: 'callback',
params: { city: cityName },
callback: function (data) {
parking.stores.parkingFacilityByCity.loadData(data.Root);
}
});
};
Hope this helps some one. There may be other methods too. But this is the one which worked for me pretty well.
希望这对某人有所帮助。也可能有其他方法。但这对我来说非常有用。