0

有谁知道如何在 Xpages 中构建 dojox Tree Grid。我试图根据http://xcellerant.net提供的信息制作一个网格。我已经创建了从数据库视图加载数据的 xAgent,但是当我加载测试页面时出现错误。

这是从视图加载数据的 xAgent 的代码

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:this.afterRenderResponse><![CDATA[#{javascript:// Read view data and write out the JSON data for the categorized grid
// Each view entry is written out at the top level, but each category has a children property that is an array of IDs of child entries to indent.
// There can be any number of categorization levels -- just add 'children' properties to child entries.
// NOTE: It needs the newlines after each line between the write() statements or the browser doesn't see the output as JSON

var externalContext = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = externalContext.getResponse();

response.setContentType('application/json');
response.setHeader('Cache-Control', 'no-cache');

writer.write("{\n");
writer.write("identifier: 'id',\n");
writer.write("label: 'name', \n");
writer.write("items: [\n");

var categoryItem = "";
var childItems = "";

// Walk the view and build the JSON data
var vw:NotesView = database.getView('Vrakkoder');
var nav:NotesViewNavigator = vw.createViewNav();
var ve:NotesViewEntry = nav.getFirst();

while (ve != null) {
    var cv = ve.getColumnValues();

    // When a categorized entry is reached:
    // (a) write out the previous category and children
    // (b) set up the new category element  
    if (ve.isCategory()) {
        // Write out the previous category and child entries        
        if (categoryItem != "") {
            // Trim the trailing comma and space off the category item. 
            // (The child items still need to end with a comma before the next category item starts.)
            categoryItem = categoryItem.substring(0, categoryItem.length - 2);
            writer.write("\n" + categoryItem + "] }, \n" + childItems);
        }   

        // Start building the new category and child entries
        categoryItem = "  {id:'" + cv[0] + "', type: 'vrakgruppe', vrakgruppe:'" + cv[0] + "', children:[";
        childItems = "";

    } else {
        // This isn't a category, so simultaneously build the children property and the child entries, until the next category is reached.
        categoryItem += "{_reference:'" + ve.getUniversalID() + "'}, ";
        childItems += "{id:'" + ve.getUniversalID() + "', vrakode:'" + cv[1] + "', vrak_aarsak_kode:'" + cv[2] + "'}, "

    }   

    // Get the next entry and recycle the current one
    var tmpentry = nav.getNext();
    ve.recycle();
    ve = tmpentry;
}


// Write out the last category and children, without the trailing commas
categoryItem = categoryItem.substring(0, categoryItem.length - 2);
childItems = childItems.substring(0, childItems.length - 2);
writer.write("\n" + categoryItem + "] }, \n" + childItems);

// Close the JSON string
writer.write("]}");
writer.endDocument();}]]></xp:this.afterRenderResponse>
</xp:view>

这是在 xpage 中生成树形网格的代码

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xe="http://www.ibm.com/xsp/coreex" dojoParseOnLoad="true"
    dojoTheme="true">

    <xp:this.resources>
        <xp:dojoModule name="dojox.grid.TreeGrid"></xp:dojoModule>
        <xp:dojoModule name="dijit.tree.ForestStoreModel"></xp:dojoModule>
        <xp:dojoModule name="dojo.data.ItemFileWriteStore"></xp:dojoModule>

        <xp:styleSheet
            href="/.ibmxspres/dojoroot/dojox/grid/resources/Grid.css">
        </xp:styleSheet>
        <xp:styleSheet
            href="/.ibmxspres/dojoroot/dijit/themes/tundra/tundra.css">
        </xp:styleSheet>
        <xp:styleSheet
            href="/.ibmxspres/dojoroot/dojox/grid/resources/tundraGrid.css">
        </xp:styleSheet>
    </xp:this.resources>


    <div id="treeGrid"></div>

    <xp:eventHandler event="onClientLoad" submit="false">
        <xp:this.script><![CDATA[var layout = [
  { name: "Vrakgruppe", field: "vrakgruppe"},
  { name: "Vrakkode", field: "vrakkode"},
  { name: "Vrak aarsak kode", field: "Vrak_aarsak_kode"}
];

var jsonStore = new dojo.data.ItemFileWriteStore({ url: "TreeGrid_DataStore.xsp"});

var treeModel = new dijit.tree.ForestStoreModel({
  store: jsonStore,
  query: {type: 'vrakgruppe'},
  rootId: 'groupRoot',
  rootLabel: 'Group',
  childrenAttrs: ['children']
});

var grid = new dojox.grid.TreeGrid({
  treeModel: treeModel,
  structure: layout
}, 'treeGrid');

grid.startup();

dojo.connect(window, "onresize", grid, "resize");]]></xp:this.script>
    </xp:eventHandler></xp:view>

有人能帮我吗。我被困住了。

4

1 回答 1

1

您非常接近您的解决方案。您唯一需要添加的是rendered="false"您的 XAgent “TreeGrid_DataStore.xsp”

在此处输入图像描述

如果没有此参数,您的 XAgent 不仅会提供网格数据,还会提供一些额外的标头信息。当您在浏览器中打开 XAgent 时,您可以看到不同之处 - 有和没有rendered="false"

于 2013-07-20T09:29:52.523 回答