-
2 Apr 2012 5:13 AM #1
variable different scope
variable different scope
Hi,
this is my code.
I need to read records variable when i use dblclick event
...
success: function (response) {
if (response.responseText!='') {
var records = Ext.decode( response.responseText );
var count = records.length;
var i=0;
for(i=0;i<count;i++) {
var obj = [
{
id: 'portlet_'+records[i].id,
itemId: 'portlet_'+records[i].id,
title: records[i].title,
items: Ext.create(records[i].portletClass),
height:200,
listeners: {
render: function(c){
c.el.on('dblclick', function(){
if (typeof currOspite!="undefined"){
//here i need to read records variable
creaWin(records[i].id,records[i].title);
}
});
}}
}
];
items_to_load.push(obj);
}
}
}
});
...
-
2 Apr 2012 6:38 AM #2
Have a look at the data and items objects
var jsonData = Ext.util.JSON.decode(xhr.responseText);
jsonData.data
jsonData.data.items
Use firebug to see your data coming back from your server.
Regards,
Scott.
-
2 Apr 2012 7:00 AM #3
Sorry but I'dont' understand how i can read the variable "records" declared above..
..
//here i need to read records variable
creaWin(records[i].id,records[i].title);
...
-
2 Apr 2012 12:36 PM #4
Assuming you have a table with abbr,name populated with states
// make ajax call
return data from serverCode:handler: function() { Ext.Ajax.request({ method: 'POST', url: 'list.php', scope: this, // so we can access ref of field below success: function(xhr) { jsonData = Ext.JSON.decode(xhr.responseText); var records = jsonData.data; // data return from server; see below console.log(records.length); //50 console.log(records[0].abbr); // AL console.log(records[0].name); // Alabama } }); }
Regards,Code:listData('states'); function listData($table) { $sql = 'SELECT * FROM '.$table; $result = mysql_query($sql); while($rec = mysql_fetch_array($result, MYSQL_ASSOC)){ $arr[] = $rec; }; $rows = 50; // hard coded for this example $data = json_encode($arr); //encode the data in json format echo $cb . '({"total":"' . $rows . '","data":' . $data . '})'; }
Scott.
-
3 Apr 2012 12:18 AM #5
I resolved... but I'm not sure it's the correct solution.
render: function(c){
c.el.on('dblclick', function(){
if (typeof currOspite!="undefined"){
creaWin(records[0].id,records[0].title);
}
});
}}


Reply With Quote