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

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

问题描述

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

在$ C $下我的剧本是::

 <脚本>
传播populateGrid(){
    dojo.xhrGet({
        网址:HTTP://本地主机:8080 / 2_8_2012 / JSP / GetJson.jsp
        负载:fillGrid,
        错误:handleError的,
        preventCache:真
        });
}

功能fillGrid(数据,ioArgs)
{
    警报(数据);
        VAR newData = {
            标识符:ID,
            项目:数据
    };

    VAR数据存储=新dojo.data.ItemFileReadStore({数据:newData,ID:dataStoreId});
    变种gridStructure = [[

                          {场:ID,
                                名称:ID_Emp
                                宽度:20%,
                                班:名字
                          },
                          {
                              现场:名字,
                              名称:姓名,
                              宽度:20%,
                              班:名字
                          },
                          {场:电子邮件,
                                名称:邮件,
                                宽度:20%,
                                班:名字
                          }

                    ]
              ]。

    变种网格= dijit.byId(grid.DataGrid);
    grid.setStore(数据存储);
    grid.startup();
}

功能handleError的(){
    (在调用该服务时发生错误。)警报;
}
< / SCRIPT>
 

现在,这里戒备(数据)和 HTTP输出://本地主机:8080 / 2_8_2012 /jsp/GetJson.jsp 是相同的,即::

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

我的xhr.get功能工作正常,数据检索方面。即当我在一个数据库中更新值。我得到的警报(数据)输出与更新后的值,而无需再次刷新整个页面。但数据不会显示在数据网格中。

我收到警报

 在调用该服务时发生错误。
 

在$ C $下的http://本地主机:8080 / 2_8_2012 / JSP /的getJSON。 JSP 是::

 &LT;%@页面语言=Java的的contentType =应用/ JSON的;字符集= ISO-8859-1
    的pageEncoding =ISO-8859-1%&GT;
    &LT;%@页面进口=MyPackage.PopulateTextbox%&GT;
&LT;%
字符串temp1中;
PopulateTextbox OBJ =新PopulateTextbox();
temp1中= obj.method();
%&GT;
&LT;%= temp1目录%&GT;
 

的标记code是::

 &LT; D​​IV ID =grid.DataGrid数据道场型=dojox.grid.DataGrid称号=简单网格数据道场道具=autoWidth:如此,结构:gridStructure的风格=宽度:900px;高度:200像素;&GT;&LT; / DIV&GT;

&LT; D​​IV ID =contentpaneid的dojoType =dijit.layout.ContentPane称号=挂起的活动的风格=背景图像:网址(HTTP://本地主机:8080 / 2_8_2012 /图片/ 17.png) ;的onclick =populateGrid&GT;
 

我没有得到什么问题。 u能请帮助我,为什么我会收到错误警报。谢谢。

解决方案

PRATIK钱德拉正确地提到这个问题 - 数据网格被填充,而不设置任何商店。我建议改变你的DataGrid来填充编程

所以,你的宣言:

 &LT; D​​IV ID =grid.DataGrid数据道场型=dojox.grid.DataGrid
 

neeeds更改为:

 &LT; D​​IV ID =mygrid&GT;&LT; / DIV&GT;
 

,然后更改行:

  VAR电网= dijit.byId(grid.DataGrid);
 

  VAR电网=新dojox.grid.DataGrid({
                ID:网格,
                jsid:网格,
                商店:数据存储,
                结构:gridStructure,
                风格:宽度:900px;高度:300像素;
            },dojo.byId(mygrid));
grid.startup();
 

另外请注意,只要你想刷新网格中的数据,则不需要重新填充网格,你可以用新值更新和DataGrid中的数据存储会自动用新的数据更新:-)道场负责其中的一部分。

要清除现有数据,在数据存储,并与新的数据来填充它,设置你的国际财务报告准则的clearOnClose财产。参见:<一href="http://stackoverflow.com/questions/9317984/updating-dojo-dijit-filteringselects-store-with-asynchonous-data">Updating道场Dijit的地方是FilteringSelect的商店与asynchonous数据了解clearOnClose

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.

The code for my script is ::

<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>

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"}]

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.

I am receiving an alert

An error occurred while invoking the service.

The code for http://localhost:8080/2_8_2012/jsp/GetJson.jsp is ::

<%@ 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 %>

The markup code is ::

<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 rightly alluded to the issue - the datagrid is being populated without any store being set. I suggest changing your datagrid to be populated programmatically

So your declaration:

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

neeeds to be changed to:

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

and then change the line:

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();

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.

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天全站免登陆