如何在同一页面上使用jit spacetree和jqgrid?

时间:2014-02-18 11:31:27

标签: javascript jquery asp.net ajax jqgrid

我有一页我需要jit Spacetree和jqgrid。但它正确地显示了jqgrid或Spacetree。我正在通过ajax请求加载带有json数据的Spacetree。 root节点永远不会出现,但所有其他节点都会出现并且它完全正常运行。如果我删除jqgrid包含然后树加载根节点。 我使用过spacetree的这个例子

http://philogb.github.io/jit/static/v20/Jit/Examples/Spacetree/example2.html

我用这个函数替换了3行example2.js

 st.loadJSON(eval(  $.parseJSON(json)));
st.compute();
st.onClick(st.root);

获取json数据的函数

$.ajax({
       type: "POST",
       url: "../default.aspx",
       data: {Mode: 'Tree'},
       dataType: "text",
       success: function(response) {
              var response = $.parseJSON(response);

                  //load json data
                   st.loadJSON(response);

                    //compute node positions and layout
                    st.compute();
                    //optional: make a translation of the tree
                  //  st.geom.translate(new $jit.Complex(-200, 0), "current");
                    //emulate a click on the root node.
                    st.onClick(st.root);
                   // NodeId=st.root;

        },
        error: function(rs, e) {
               //alert(rs.responseText);
               return false;
        }
  }); 

我使用过这个jqgrid

http://jsfiddle.net/amorris/yNw3C/

我在html中包含了以下文件

  • jqgrid-4.4.5-src / ui.jqgrid.css,
  • jqgrid-4.4.5-src / jquery.jqGrid.js,
  • jqgrid-4.4.5-src / jquery-ui.css,
  • 的jqGrid-4.4.5-SRC / grid.locale-en.js,

1 个答案:

答案 0 :(得分:0)

这是因为jqgrid和spacetree使用的命名约定。两者都创造了相同的ID。 jqgrid正在创建一个id = 1的行,而spacetree也在创建一个id = 1的div。现在,在创建树的节点时,dom通过id获取div。因为jqgrid首先加载所以dom获得了jqgrid行的id而不是div。我通过添加前缀来更改jqgrid id创建过程。现在它正在发挥作用。