dojox.data.Datagrid上的数据没有显示在点击事件上。 [英] Data is not getting displayed in dojox.data.Datagrid on click event.

查看:74
本文介绍了dojox.data.Datagrid上的数据没有显示在点击事件上。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在数据网格中显示数据。数据由URL使用$ .get方法作为JSon类型检索。我没有得到任何错误。但是没有获得数据网格。这是我的脚本代码::

 < script type =text / javascript> 
$(document)。ready(function(){
$('#contentpaneid')bind('click',getInfoFromServer);
function getInfoFromServer(){
$ .get(http:// localhost:8080 / 2_8_2012 / jsp / GetJson.jsp?random =+ new Date()。getTime(),function(result){
success:postToPage ,
alert('Load was perform。');
},Json);

function postToPage(data){
alert(data);
var storedata = {
identifier:ID,
items:data //[{\"ID\":1,Names:Shantanu\",\"电子邮件:shantanu.tomar @ gmail.com},{ID:2,名称:Mayur,电子邮件:mayur.sharma@gmail.com},{ID:3,名称:Rohit },{ID:21,名称:Rakesh,电子邮件:askjhjk}]

};

var store1 = new dojo .data.ItemFileWriteStore({data:storedata});
var gridStructure = [[

{field:ID,
name:ID_Emp,
宽度:20%,
类:firstName
},
{
字段:名称,
名称:名称,
宽度:20%,
类:firstName
},
{field:电子邮件,
名称:邮件,
宽度: 20%,
类:firstName
}

]
];

var grid = new dojox.grid.DataGrid({

store:store1,
structure:gridStructure,
rowSelector:'30px',
selectionMode:single,
autoHeight:true,
columnReordering:true

},'gridDiv');


grid.startup();
dojo.connect(grid,onSelectionChanged,grid,function(){
var items = grid.selection.getSelected();



//使用所选项目执行某些操作
dojo.forEach(items,function(item){
var v = grid.store.getValue(item,Names);

function showDialog(){
dojo.require('dijit.Tooltip');
dijit.byId(terms)。show();
}

showDialog();
},grid);

});


dojo.connect(grid,onCellClick,grid,function sendmail(){
var items = grid.selection.getSelected();

dojo.forEach(items,function(item){
var v1 = grid.store.getValue(item,Email);
alert(v1);
request.setAttribute variablemail,v1);
});
});

};
};
});
< / script>

我的标记代码是::

 < div id =contentpaneiddojoType =dijit.layout.ContentPanetitle =待定活动style =background-image:url('http:// localhost:8080 / 2_8_2012 / images / 17.png');> 

< div data-dojo-id =gridDivtitle =简单网格style =width:900px; height:200px;>

当我点击内容窗格内部时,我得到我的警报(数据)输出作为检索数据作为JSon $ .get方法::

  [Object object] [Object object] [Object object]([Object object]取决于数据库中的条目数量)

在以文本形式检索数据时输出::

  [{ID:1,名称:Shantanu,电子邮件:shantanu.tomar@gmail.com },{ID:2,名称:Mayur,电子邮件:mayur.sharma@gmail.com},{ID:3,名称:Rohit},{ ID:21,名称:Rakesh,电子邮件:askjhjk},{ID:22,名称:你好}] 
/ pre>

现在,当我更新数据时,我得到我的数据警报ryt。即值得在alert(数据)中更新我的$ .get函数正常工作。并且还得到警报(已执行加载)消息。但是网格没有被显示。它不是数据,但网格也没有显示。点击只有警告框出现。而已。我在哪里犯错?我应该以text或JSON的形式检索数据,以便将值正确传递给items:。请帮忙。我希望在点击事件上,网格根据数据库的变化刷新自身。谢谢。

解决方案

更改

  < div data-dojo-id =gridDiv... 

to

 < div id =gridDiv... 

请注意,data-dojo-id旨在用于创建一个保存该窗口小部件的全局JS变量。
在你的情况下,你填充datagrid,并要求dojo用id gridrid替换一个id为gridDiv的DOM节点。因为dojo不能找到这样一个节点,你没有看到datagrid $ /

I want to display data in a data grid. The data is retrieved by a URL using $.get Method as a JSon type. I am not getting any error. But not getting Data grid as well. Here's me script code ::

<script type="text/javascript">
$("document").ready(function(){
    $('#contentpaneid').bind('click', getInfoFromServer);
    function getInfoFromServer(){
        $.get("http://localhost:8080/2_8_2012/jsp/GetJson.jsp?random=" + new Date().getTime(), function (result) {
            success:postToPage(result),
            alert('Load was performed.');
            },"Json");

    function postToPage(data){
    alert(data);    
    var storedata = {
        identifier:"ID",
        items: data //[{"ID":1,"Names":"Shantanu","Email":"shantanu.tomar@gmail.com"},{"ID":2,"Names":"Mayur","Email":"mayur.sharma@gmail.com"},{"ID":3,"Names":"Rohit"},{"ID":21,"Names":"Rakesh","Email":"askjhjk"}] 

};

    var store1 = new dojo.data.ItemFileWriteStore({data: storedata}) ;
    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 = new dojox.grid.DataGrid({

        store: store1,
        structure: gridStructure,
        rowSelector: '30px',
        selectionMode: "single",
        autoHeight:true,
        columnReordering:true

        },'gridDiv');


    grid.startup();
    dojo.connect(grid, "onSelectionChanged", grid, function(){
                var items = grid.selection.getSelected();



            //  do something with the selected items
                dojo.forEach(items, function(item){
                    var v = grid.store.getValue(item, "Names");

                    function showDialog() {
                        dojo.require('dijit.Tooltip');
                        dijit.byId("terms").show();
                    }

                    showDialog();
                    }, grid);

            });


            dojo.connect(grid, "onCellClick", grid, function sendmail(){
                var items = grid.selection.getSelected();

                dojo.forEach(items, function(item){
                    var v1 = grid.store.getValue(item, "Email");       
                    alert(v1);
                    request.setAttribute("variablemail", v1);
            });
    });

};
};
});
</script>

My markup code is ::

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

<div data-dojo-id="gridDiv" title="Simple Grid" style="width:900px; height:200px;">

When i click inside content pane I get my alert(data) output as when retrieving data as JSon through $.get method ::

[Object object][Object object][Object object](The number of [Object object] depends on number of entries in Database)

And output when Retrieving data as Text is ::

[{"ID":1,"Names":"Shantanu","Email":"shantanu.tomar@gmail.com"},{"ID":2,"Names":"Mayur","Email":"mayur.sharma@gmail.com"},{"ID":3,"Names":"Rohit"},{"ID":21,"Names":"Rakesh","Email":"askjhjk"},{"ID":22,"Names":"Hello"}]

Now when i update the data I do get my data alert ryt. i.e value is getting updated in alert(data) my $.get function is working fine. And also getting alert('Load was performed.') message. But grid is not getting displayed. Its not the data .but grid is also not getting displayed. On click only alert boxes appear. that's it. Where am i making mistake ? And i should retrieved the data as text or JSON so that values are correctly passed on to "items:". please help. i want that on click event the grid refreshes itself according to changes in database. Thanks.

解决方案

Change

<div data-dojo-id="gridDiv"...

to

<div id="gridDiv" ...

Note that data-dojo-id is meant to be used to create a global JS variable that holds the widget. In your situation, you are populating the datagrid and asking dojo to replace a DOM node with id gridDiv with the datagrid. Since dojo is not able to find such a node, you are not seeing the datagrid

这篇关于dojox.data.Datagrid上的数据没有显示在点击事件上。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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