使用dojo.xhrget()方法在Dojogrid中显示数据 [英] Displaying Data in Dojogrid using dojo.xhrget() method

查看:342
本文介绍了使用dojo.xhrget()方法在Dojogrid中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一组数据,我通过使用dojo.xhrget()方法对服务器进行异步调用来检索。我通过URL检索数据,我希望每次用户在内容窗格中点击一组新的值,而不刷新整个页面。问题是数据没有显示在网格中。我收到一个错误xhrget()错误的方法。

I want to display a set of data which i am retrieving by an asynchronous call to the server using dojo.xhrget() method. I am retrieving data through a URL and i want that everytime a user clicks in content pane a new set of values gets displayed in grid without refreshing whole page. The problem is that data is not getting displayed in Grid. I am receiving an error by xhrget() error method.

我的脚本代码是::

<script>
function populateGrid(){
    dojo.xhrGet({
        url: "http://localhost:8080/2_8_2012/jsp/GetJson.jsp",
        load: fillGrid,
        error:handleError,
        preventCache:true
        });
}

function fillGrid(data, ioArgs)
{
    alert(data);
        var newData = {
            identifier: "ID",
            items: data
    };

    var dataStore = new dojo.data.ItemFileReadStore({data: newData, id:"dataStoreId"});
    var gridStructure =[[

                          { field: "ID",
                                name: "ID_Emp",
                                width: "20%",
                                classes:"firstName"
                          },
                          {
                              field: "Names",
                              name: "Name",
                              width: "20%",
                              classes: "firstName"
                          },
                          { field: "Email",
                                name: "Mail",
                                width: "20%",
                                classes:"firstName"
                          }

                    ]
              ];

    var grid = dijit.byId("grid.DataGrid");     
    grid.setStore(dataStore);
    grid.startup();
}

function handleError() {
    alert("An error occurred while invoking the service.");
}
</script>

现在,这里是alert(data)和 http:// localhost:8080 / 2_8_2012 / jsp / GetJson.jsp 是相同的ie ::

Now , here the output of alert(data) and http://localhost:8080/2_8_2012/jsp/GetJson.jsp is same i.e ::

[{"ID":1,"Names":"Shantanu","Email":"shantanu.tomar@gmail.com"},{"ID":2,"Names":"Mayur","Email":"mayur.sharma@gmail.com"},{"ID":26,"Names":"Rohit"}]

我的xhr.get功能在数据检索方面工作正常。即当我更新数据库中的值时。我使用该更新的值获取警报(数据)输出,而不会再次刷新整个页面。但数据不会显示在数据网格中。

My xhr.get function is working fine in terms of data retrieval. i.e when i update the values in a database. I do get the alert(data) output with that updated value without refreshing the whole page again. But data is not displayed in Data grid.

我正在收到一个提醒

An error occurred while invoking the service.

http:// localhost:8080 / 2_8_2012 / jsp / GetJson.jsp 是::

<%@ page language="java" contentType="application/json; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page import="MyPackage.PopulateTextbox" %>
<%
String temp1;
PopulateTextbox obj = new PopulateTextbox();
temp1 = obj.method();
%>
<%=temp1 %>

标记代码是::

<div id="grid.DataGrid" data-dojo-type="dojox.grid.DataGrid"  title="Simple Grid" data-dojo-props= "autoWidth:true, structure: gridStructure" style="width:900px; height:200px;"></div>

<div id="contentpaneid" dojoType="dijit.layout.ContentPane" title="Pending Activities" style="background-image: url('http://localhost:8080/2_8_2012/images/17.png');" onclick="populateGrid">

我没有得到什么问题。你可以帮我解决为什么我收到一个错误警报。谢谢。

I am not getting what's the problem. Can u please help me out on why am i getting an error alert. thanks.

推荐答案

Pratik Chandra正确地提到了这个问题 - 数据网格正在填充,没有设置任何商店。我建议你改变你的datagrid以编程方式填充

Pratik Chandra rightly alluded to the issue - the datagrid is being populated without any store being set. I suggest changing your datagrid to be populated programmatically

所以你的声明:

<div id="grid.DataGrid" data-dojo-type="dojox.grid.DataGrid" 

要更改为:

<div id="mygrid" ></div>

然后更改行:

var grid = dijit.byId("grid.DataGrid");

to:

var grid = new dojox.grid.DataGrid({
                id: "grid",
                jsid: "grid",
                store: dataStore,
                structure: gridStructure,
                style: 'width:900px;height:300px;'
            }, dojo.byId("mygrid"));
grid.startup();

另请注意,只要您要刷新网格中的数据,就不需要重新填充网格,您可以使用新值更新数据存储区,并且datagrid将自动刷新新数据:-) Dojo负责该部分。

Also note that whenever you want to refresh the data in the grid, you do not need to repopulate the grid, you can just update the datastore with new values and the datagrid will automatically refresh with new data :-) Dojo takes care of that part.

清除现有数据数据存储并使用新数据填充数据,请在您的IFRS上设置clearOnClose属性。请参阅:使用异步数据更新Dojo Dijit FilteringSelect的商店,以学习关于clearOnClose

To clean existing data in the datastore and populate it with new data, set the clearOnClose property on your IFRS. See: Updating Dojo Dijit FilteringSelect's store with asynchonous data to learn about clearOnClose

这篇关于使用dojo.xhrget()方法在Dojogrid中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆