DataGrid in Dojo , with json data from a servlet

前端 未结 2 1216
[愿得一人]
[愿得一人] 2021-01-01 04:20

I am using JSON for first time... and want to fill my datagrid with my JSON data, this is my JSON data :

{
  \"head\": {
    \"vars\": [ \"s\" , \"fname\" ,          


        
2条回答
  •  旧巷少年郎
    2021-01-01 04:41

    There is a mistake in load call, it is an async call then when you try to build the grid you don't have the data and the store cannot be built as needed. You can include everything in load function as shown below:

    var items,store;
        var ss = dojo.xhrGet({
            url: "http://localhost:8477/E-Governance/listPerson", 
            handleAs: "json", 
            preventCache: true,
            load: function(data){
                items = dojo.map(data.results.bindings, function(binding) {
                    return {
                        fname : binding.fname.value, 
                        lname : binding.lname.value
                    };                    
                });
                store =  new dojo.data.ItemFileReadStore({           
                    data : {
                        items : items
                    }
                });             
                console.log(items[0].fname+' '+items[0].lname);  
                _createGrid(sore);
    
            }
        });
    
        console.log('3-4');
    

提交回复
热议问题