YUI Treeble Toggle() 展开或折叠

标签 yui

我一直在努力自动扩展树形节点,但没有成功。我查看了发现的文档 here ,但无法找到工作示例或使我的示例工作。提到了 openNodeKey 项,但我找不到任何文档来指出正确的方向。

<script type="text/javascript">
YUI({
//  filter: 'raw', combine: false,
    gallery: 'gallery-2012.10.31-20-00'
}).use(
    'datatable', 'datasource-arrayschema',
'gallery-treeble', 'gallery-paginator',
function(Y)
{
function sendRequest()
{
    table.datasource.load(
    {
        request:
        {
            startIndex:  pg.getStartIndex(),
            resultCount: pg.getRowsPerPage()
        }
    });
}

// column configuration

var cols =
[
    {
        key: 'treeblenub',
        label: '&nbsp;',
        nodeFormatter: Y.Treeble.buildTwistdownFormatter(sendRequest)
    },
    {
        key: 'title',
        label: 'Building',
        formatter: Y.Treeble.treeValueFormatter,
        allowHTML: true
    },
    { key: 'arrivals',          label: 'Visitors #'  },
    { key: 'occupancy_number',  label: 'Occupancy #', allowHTML: true },
    { key: 'occupancy_percent', label: 'Occupancy %', allowHTML: true },
    { key: 'max_capacity',      label: 'MAX Capacity' }
];

// raw data

var data =


[{title:"North Building",arrivals:"", occupancy_number:"0", max_capacity:"2000",     occupancy_percent:"0%",
    kiddies:
    [{title:"Level 1", arrivals:"", occupancy_number:"0",max_capacity:"500", occupancy_percent:"0%" },{title:"Level 2", arrivals:"", occupancy_number:"0",max_capacity:"500", occupancy_percent:"0%" },{title:"Level 3", arrivals:"", occupancy_number:"0",max_capacity:"500", occupancy_percent:"0%" },{title:"Level 4", arrivals:"", occupancy_number:"0",max_capacity:"500", occupancy_percent:"0%" } ]}, 

    {title:"East Building",arrivals:"0", occupancy_number:"0", max_capacity:"0", occupancy_percent:"0%",
        kiddies:
        [
            {title:"Level 1", arrivals:"0", occupancy_number:"0", max_capacity:"0", occupancy_percent:"0%" },
            {title:"Level 2", arrivals:"0", occupancy_number:"0", max_capacity:"0", occupancy_percent:"0%" },
            {title:"Level 3", arrivals:"0", occupancy_number:"0", max_capacity:"0", occupancy_percent:"0%" }
        ]},

    {title:"West Building",arrivals:"0", occupancy_number:"0", max_capacity:"0", occupancy_percent:"0%",
        kiddies:
        [
            {title:"Level 1", arrivals:"0", occupancy_number:"0", max_capacity:"0", occupancy_percent:"0%" },
            {title:"Level 2", arrivals:"0", occupancy_number:"0", max_capacity:"0", occupancy_percent:"0%" },
            {title:"Level 3", arrivals:"0", occupancy_number:"0", max_capacity:"0", occupancy_percent:"0%" }            ]},

];



// treeble config to be set on root datasource

var schema =
{
    resultFields:
    [
        "arrivals","occupancy_number","max_capacity","occupancy_percent","title",
        {key: 'kiddies', parser: 'treebledatasource'}
    ]
};

var schema_plugin_config =
{
    fn:  Y.Plugin.DataSourceArraySchema,
    cfg: {schema:schema}
};

var treeble_config =
{
    generateRequest:        function() { },
    schemaPluginConfig:     schema_plugin_config,
    childNodesKey:          'kiddies',
    totalRecordsReturnExpr: '.meta.totalRecords'
};

// root data source

var root            = new Y.DataSource.Local({source: data});
root.treeble_config = Y.clone(treeble_config, true);
root.plug(schema_plugin_config);

// TreebleDataSource

var ds = new Y.TreebleDataSource(
{
    root:             root,
    paginateChildren: true,
    uniqueIdKey:      'title'   // normally, it would a database row id, but title happens to be unique in this example
});

// Paginator

var pg = new Y.Paginator(
{
    totalRecords: 1,
    rowsPerPage: 20,
    rowsPerPageOptions: [1,2,5,10,25,50],
    template: '' // {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} <span class="pg-rpp-label">Rows per page:</span> {RowsPerPageDropdown}'
});
// pg.render('#pg');

pg.on('changeRequest', function(state)
{
    this.setPage(state.page, true);
    this.setRowsPerPage(state.rowsPerPage, true);
    this.setTotalRecords(state.totalRecords, true);
    sendRequest();
});

ds.on('response', function(e)
{
    pg.setTotalRecords(e.response.meta.totalRecords, true);
    pg.render();
});

// DataTable

var table = new Y.Treeble({columns: cols});
table.plug(Y.Plugin.DataTableDataSource, {datasource: ds});

table.datasource.get('datasource').toggle([1],0,null);

table.render("#treeble");

sendRequest();
});
</script>

最佳答案

文档有点稀疏,但是nodeOpenKey is mentioned .

basic example ,nodeOpenKey 定义为“_open”。如果您搜索_open,您将看到它嵌入在数据中。具有 _open:true 的节点在首次查看时处于打开状态。

关于YUI Treeble Toggle() 展开或折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16864629/

相关文章:

javascript - 使用带自动完成功能的 YUI 布局

datatable - 如何使用按钮刷新 YUI 数据表?

jquery-ui - 自定义 Grails 生成的 View

c++ - 为 c++ 和 YUI 创建 gui 绑定(bind)

javascript - 展开/折叠一个 div 元素?

javascript - 为什么这不是有效的代码?

javascript - 如何使用 YUI 进行同步/阻塞 XMLHttpRequest

calendar - 音频 : Event rendering issue in month view

javascript - 外部 JavaScript 文件必须是什么样子才能避免全局变量和方法?

javascript - 如何禁用 YUI 节点上的单击处理程序?