javascript - How can I get my tree data loaded in my ExtJS tree panel? -


i have extjs 4.2 treepanel, when call php code data, data not loaded tree.

the data call success, , i'm getting response, tree data not loading tree.

function ongetdata(data) {     alert('ongetdata');     alert(data); }; ext.onready(function() {     ext.create('ext.tree.panel', {         title: 'tree refresh example',         width: 300,         height: 350,         listeners: {             afterrender: function() {                 this.store.getdata(ongetdata, this);             }         },         tbar: ['->', {              xtype: 'button',              text: 'add banana',             value: 1,             margin: '0 30 0 0',             listeners: {                 click: function(comp) {                     senddata(comp.value);                 }             }         }, {              xtype: 'button',              text: 'add cabbage',             value: 2,             margin: '0 30 0 0',             listeners: {                 click: function(comp) {                     senddata(comp.value);                 }             }         }, {              xtype: 'button',              text: 'add yogurt',             value: 3,             listeners: {                 click: function(comp) {                     senddata(comp.value);                 }             }         }, '->'],         renderto: 'content',         store: new sampletreedata()     });         });    ext.define('sampletreedata', {     extend: 'ext.data.treestore',     proxy: {         type: 'ajax',         url : '',         reader: {             type: 'json',             root: 'root'         }     },     getdata: function(callback, scope) {         alert('getdata');         var store = this;         store.proxy.url = 'data.php?mode=getdata';         scope.collapseall();         store.load({             scope : scope,             callback : function(records, operation, success) {                 if (ext.isfunction(callback)) {                     callback(store, scope, records, success);                 }             }         });     }    });   <?php $data = 'root: {' .         'text: "tree root",' .         'expanded: true,' .         'children: [' .             '{' .                 'text: "fruits",' .                 'children: [' .                     '{ leaf:true, text: "apple" },' .                     '{ leaf:true, text: "orange" }' .                 ']' .             '},' .             '{' .                 'text: "vegetables",' .                 'expanded: false,' .                 'children: [' .                     '{ leaf:true, text: "carrot" },' .                     '{ leaf:true, text: "beet" }' .                 ']' .             '},' .             '{' .                 'text: "dairy",' .                 'children: [' .                     '{ leaf:true, text: "milk" },' .                     '{ leaf:true, text: "cheese" }' .                 ']' .             '}' .         ']' .     '}'; $logref = fopen('data.log', 'w'); fwrite($logref, "entered script.\n");   if(isset($_post['data'])){     fwrite($logref, "senddata\n");     return 'senddatasuccess'; }else {     fwrite($logref, "getdata\n");     echo json_encode(utf8_encode($data)); } fclose($logref); ?>  <!doctype html public "-//w3c//dtd html 4.01//en" "http://www.w3.org/tr/html4/strict.dtd"> <html> <head>     <link rel="stylesheet" type="text/css" href="../../../../ext-4.2.2.1144/resources/css/ext-all.css" />     <script type="text/javascript" src="../../../../ext-4.2.2.1144/ext-all-debug.js"></script>     <script type="text/javascript" src="refresh1.js"></script>     <script type="text/javascript" src="sampletreedata.js"></script> </head> <body style="width: 100%; height: 100%; margin: 0px; padding: 0px; background-color: #89e5bd;">     <div id="content" style="margin: auto; width: 500px; height: 500px;"/> </body> 

solved

got working changing php, , setting rootvisible false on treepanel.

i changed tree store bit.

ext.define('sampletreedata', {     extend: 'ext.data.treestore',     autoload: false,     autosync: false,     proxy: {         type: 'ajax',         url : '',         reader: {             type: 'json',             root: ''         }     },     root: {         expanded: true     },       getdata: function(callback, scope) {         var store = this;         store.proxy.url = 'data.php?mode=getdata';         store.load({             scope : scope,             callback : function(records, operation, success) {                 if (ext.isfunction(callback)) {                     callback(store, scope, records, success);                 }             }         });     }    });  <?php $data = '[{' .         'text: "tree root",' .         'expanded: true,' .         'children: [' .             '{' .                 'text: "fruits",' .                 'children: [' .                     '{ leaf:true, text: "apple" },' .                     '{ leaf:true, text: "orange" }' .                 ']' .             '},' .             '{' .                 'text: "vegetables",' .                 'expanded: false,' .                 'children: [' .                     '{ leaf:true, text: "carrot" },' .                     '{ leaf:true, text: "beet" }' .                 ']' .             '},' .             '{' .                 'text: "dairy",' .                 'children: [' .                     '{ leaf:true, text: "milk" },' .                     '{ leaf:true, text: "cheese" }' .                 ']' .             '}' .         ']' .     '}]'; $logref = fopen('data.log', 'w'); fwrite($logref, "entered script.\n");   if(isset($_post['data'])){     fwrite($logref, "senddata\n");     return 'senddatasuccess'; }else {     fwrite($logref, "getdata\n");     echo $data; } fclose($logref); ?> 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -