在click事件中,数据未显示在dojox.data.Datagrid中。

时间:2012-03-16 11:52:54

标签: javascript jquery datagrid datagridview dojox.grid.datagrid

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

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

我的标记代码是::

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

当我在内容窗格中单击时,我得到警报(数据)输出,就像通过$ .get method ::

将数据检索为JSon一样
[Object object][Object object][Object object](The number of [Object object] depends on number of entries in Database)

以Text格式检索数据时输出::

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

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

1 个答案:

答案 0 :(得分:0)

更改

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

<div id="gridDiv" ...

请注意,data-dojo-id用于创建保存小部件的全局JS变量。 在您的情况下,您正在填充数据网格并要求dojo将id为gridDiv的DOM节点替换为datagrid。由于dojo无法找到这样的节点,因此您没有看到datagrid