遅延読み込み

TreeViewは、大規模なデータソースのパフォーマンスを向上させるために、ノードと子項目を遅延して読み込むことができます。遅延読み込みを有効にするには、lazyLoadFunctionプロパティを関数に設定し、ノードが展開されたときにデータを読み込みます。このサンプルは、遅延読み込みされたノードの動作を説明します。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjNav from '@grapecity/wijmo.nav'; import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // // create the tree var tree = new wjNav.TreeView('#theTree', { itemsSource: getData(), displayMemberPath: 'header', childItemsPath: 'items', lazyLoadFunction: lazyLoadFunction }); // // function used to lazy-load node content function lazyLoadFunction(node, callback) { setTimeout(function () { var result = [ { header: 'その他の遅延ノード...', items: [] }, { header: '子ノードを含まないノード' }, { header: '子ノードを含むノード', items: [ { header: 'hello' }, { header: 'world' } ] } ]; callback(result); // return result to control }, 2500); // 2.5sec http delay } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Sample</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <div id="theTree"></div> </div> </body> </html> // start with three lazy-loaded nodes export function getData() { return [ { header: '遅延ノード 1', items: [] }, { header: '遅延ノード 2', items: [] }, { header: '遅延ノード 3', items: [] } ]; } /* default trees on this sample */ .wj-treeview { height: 350px; border: 1px solid rgba(0,0,0,0.2); } body { margin-bottom: 24pt; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjNav from '@grapecity/wijmo.nav'; // import { Component, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjNavModule } from '@grapecity/wijmo.angular2.nav'; class LazyItem { header: string; items: any[] } // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { lazyItems: LazyItem[]; items: any[] = []; lazyLoadFunction: Function; // constructor() { this.lazyItems = [ // start with three lazy-loaded nodes { header: '遅延ノード 1', items: [] }, { header: '遅延ノード 2', items: [] }, { header: '遅延ノード 3', items: [] }]; // lazy loading function this.lazyLoadFunction = this._lazyLoadFunction.bind(this); } private _lazyLoadFunction(node: wjNav.TreeNode, callback: Function) { setTimeout(function () { // simulate http delay var result = [ // simulate result { header: 'その他の遅延ノード...', items: [] }, { header: '子ノードを含まないノード' }, { header: '子ノードを含むノード', items: [ { header: 'hello' }, { header: 'world' }] } ]; callback(result); // return result to control }, 2500); // 2.5sec http delay } } // @NgModule({ imports: [WjNavModule, BrowserModule], declarations: [AppComponent], providers: [], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo TreeView Hosting GCControls</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <wj-tree-view #tvLazyLoad [itemsSource]="lazyItems" [displayMemberPath]="'header'" [childItemsPath]="'items'" [lazyLoadFunction]="lazyLoadFunction"> </wj-tree-view> </div> /* default trees on this sample */ .wj-treeview { height: 350px; border: 1px solid rgba(0,0,0,0.2); } body { margin-bottom: 24pt; } import './app.css'; import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as wjNav from '@grapecity/wijmo.react.nav'; import { getData } from './data'; class App extends React.Component { constructor(props) { super(props); this.state = getData(); } render() { return (<div className="container-fluid"> <wjNav.TreeView itemsSource={this.state} displayMemberPath="header" childItemsPath="items" lazyLoadFunction={this.lazyLoadFunction.bind(this)}></wjNav.TreeView> </div>); } lazyLoadFunction(node, callback) { setTimeout(function () { // simulate http delay var result = [ // simulate result { header: "その他の遅延ノード...", items: [] }, { header: "子ノードを含まないノード" }, { header: "子ノードを含むノード", items: [{ header: "hello" }, { header: "world" }] } ]; callback(result); // return result to control }, 2500); // 2.5sec http delay } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>AutoComplete</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> /* default trees on this sample */ .container-fluid .wj-treeview { border: 1px solid rgba(0,0,0,0.2); } body { margin-bottom: 24pt; } export function getData() { return [ { header: '遅延ノード 1', items: [] }, { header: '遅延ノード 2', items: [] }, { header: '遅延ノード 3', items: [] } ]; } <template> <div class="container-fluid"> <wj-tree-view :itemsSource="lazyItems" :displayMemberPath="'header'" :childItemsPath="'items'" :lazyLoadFunction="lazyLoadFunction" ></wj-tree-view> </div> </template> <script> import "bootstrap.css"; import "@grapecity/wijmo.styles/wijmo.css"; import Vue from "vue"; import "@grapecity/wijmo.vue2.nav"; import * as wjCore from "@grapecity/wijmo"; import { getData } from "./data"; let App = Vue.extend({ name: "app", data: function() { return { lazyItems: getData(), }; }, methods: { lazyLoadFunction:function(node, callback) { setTimeout(function() { // simulate http delay var result = [ // simulate result { header: "その他の遅延ノード...", items: [] }, { header: "子ノードを含まないノード" }, { header: "子ノードを含むノード", items: [{ header: "hello" }, { header: "world" }] } ]; callback(result); // return result to control }, 2500); // 2.5sec http delay } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <style> /* default trees on this sample */ .container-fluid .wj-treeview { border: 1px solid rgba(0,0,0,0.2); } body { margin-bottom: 24pt; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Sample</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"> </div> </body> </html> export function getData() { return [ { header: '遅延ノード 1', items: [] }, { header: '遅延ノード 2', items: [] }, { header: '遅延ノード 3', items: [] } ]; }