メニュー:コマンド

メニューコマンドはcommandプロパティを使用して作成されます。これはcanExecuteCommandおよびexecuteCommandの2つの関数プロパティを必要とするオブジェクトです。このサンプルは、InputNumberコントロールの増分値または減分値を制御するコマンドを持つMenuコントロールを示しています。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as input from '@grapecity/wijmo.input'; import * as wijmo from '@grapecity/wijmo'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // current tax value let currentTax = new input.InputNumber('#currentTax', { format: 'p2', min: 0, max: 1, step: 0.01, value: 0.08 }); // // create change tax menu let changeTax = createMenu('changeTax'); // // set command object for the tax menu changeTax.command = { // execute the command executeCommand: (arg) => { arg = wijmo.changeType(arg, wijmo.DataType.Number, null); if (wijmo.isNumber(arg)) { currentTax.value += arg; } }, // // check if a command can be executed canExecuteCommand: (arg) => { arg = wijmo.changeType(arg, wijmo.DataType.Number, null); if (wijmo.isNumber(arg)) { let val = currentTax.value + arg; return val >= 0 && val <= 1; } return false; } }; // function createMenu(elementId) { // get host element, header, items let host = document.getElementById(elementId), header = host.firstChild.textContent.trim(), items = host.querySelectorAll('div'), menuItems = []; // for (let i = 0; i < items.length; i++) { let item = items[i]; menuItems.push({ header: item.outerHTML, cmdParam: item.getAttribute('cmd-param') }); } // // clear host and instantiate menu host.innerHTML = ''; let menu = new input.Menu(host, { header: header, displayMemberPath: 'header', commandParameterPath: 'cmdParam', itemsSource: menuItems, }); // // done, return menu return menu; } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Menu Commands</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 class="form-group"> <label for="currentTax">現在の税率</label> <div id="currentTax"></div> </div> <div class="form-group"> <label for="changeTax">税率の変更</label> <div id="changeTax"> 変更量 <div cmd-param=".10">+10%</div> <div cmd-param=".05">+5%</div> <div cmd-param=".01">+1%</div> <div class="wj-separator"></div> <div cmd-param="-.01">-1%</div> <div cmd-param="-.05">-5%</div> <div cmd-param="-.10">-10%</div> </div> </div> </div> </body> </html> label { width: 120px; text-align: right; margin-right: 3px; } body { margin-bottom: 24pt; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wijmo from '@grapecity/wijmo'; // import { Component, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { tax = 0.08; command = { // execute the command executeCommand: (arg: any) => { if (wijmo.isNumber(arg)) { this.tax += arg; } }, // // check if a command can be executed canExecuteCommand: (arg: any) => { if (wijmo.isNumber(arg)) { let val = this.tax + arg; return val >= 0 && val <= 1; } return false; } }; } // @NgModule({ imports: [WjInputModule, BrowserModule], declarations: [AppComponent], 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 Menu Commands</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"> <div class="form-group"> <label for="currentTax">現在の税率</label> <wj-input-number id="currentTax" [format]="'p2'" [min]="0" [max]="1" [step]="0.01" [(value)]="tax"> </wj-input-number> </div> <div class="form-group"> <label for="changeTax">税率の変更</label> <wj-menu id="changeTax" [header]="'変更量'"> <wj-menu-item [cmd]="command" [cmdParam]="0.10">+10%</wj-menu-item> <wj-menu-item [cmd]="command" [cmdParam]="0.05">+5%</wj-menu-item> <wj-menu-item [cmd]="command" [cmdParam]="0.01">+1%</wj-menu-item> <wj-menu-separator></wj-menu-separator> <wj-menu-item [cmd]="command" [cmdParam]="-0.01">-1%</wj-menu-item> <wj-menu-item [cmd]="command" [cmdParam]="-0.05">-5%</wj-menu-item> <wj-menu-item [cmd]="command" [cmdParam]="-0.10">-10%</wj-menu-item> </wj-menu> </div> </div> label { width: 120px; text-align: right; margin-right: 3px; } body { margin-bottom: 24pt; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './app.css'; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as wijmo from '@grapecity/wijmo'; import * as wjInput from '@grapecity/wijmo.react.input'; // class App extends React.Component { constructor(props) { super(props); this.state = { tax: 0.08, command: { // execute the command executeCommand: (arg) => { arg = wijmo.changeType(arg, wijmo.DataType.Number, null); if (wijmo.isNumber(arg)) { let tax = this.state.tax; this.setState({ tax: tax += arg }); } }, // check if a command can be executed canExecuteCommand: (arg) => { arg = wijmo.changeType(arg, wijmo.DataType.Number, null); if (wijmo.isNumber(arg)) { let val = this.state.tax + arg; return val >= 0 && val <= 1; } return false; } } }; } render() { return <div className="container-fluid"> <div className="form-group"> <label htmlFor="currentTax">現在の税率</label> <wjInput.InputNumber id="currentTax" format="p2" min={0} max={1} step={0.01} value={this.state.tax}> </wjInput.InputNumber> </div> <div className="form-group"> <label htmlFor="changeTax">税率の変更</label> <wjInput.Menu header="変更量" id="changeTax" command={this.state.command}> <wjInput.MenuItem cmd={this.state.command} cmdParam={0.10}> +10% </wjInput.MenuItem> <wjInput.MenuItem cmd={this.state.command} cmdParam={0.05}> +5% </wjInput.MenuItem> <wjInput.MenuItem cmd={this.state.command} cmdParam={0.01}> +1% </wjInput.MenuItem> <wjInput.MenuSeparator></wjInput.MenuSeparator> <wjInput.MenuItem cmd={this.state.command} cmdParam={-0.01}> -1% </wjInput.MenuItem> <wjInput.MenuItem cmd={this.state.command} cmdParam={-0.05}> -5% </wjInput.MenuItem> <wjInput.MenuItem cmd={this.state.command} cmdParam={-0.10}> -10% </wjInput.MenuItem> </wjInput.Menu> </div> </div>; } } 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> label { width: 120px; text-align: right; margin-right: 3px; } body { margin-bottom: 24pt; } <template> <div class="container-fluid"> <div class="form-group"> <label for="currentTax">現在の税率</label> <wj-input-number id="currentTax" :format="'p2'" :min="0" :max="1" :step="0.01" :value="tax"> </wj-input-number> </div> <div class="form-group"> <label for="changeTax">税率の変更</label> <wj-menu id="changeTax" :header="'変更量'"> <wj-menu-item :cmd="command" :cmdParam="0.10">+10%</wj-menu-item> <wj-menu-item :cmd="command" :cmdParam="0.05">+5%</wj-menu-item> <wj-menu-item :cmd="command" :cmdParam="0.01">+1%</wj-menu-item> <wj-menu-separator></wj-menu-separator> <wj-menu-item :cmd="command" :cmdParam="-0.01">-1%</wj-menu-item> <wj-menu-item :cmd="command" :cmdParam="-0.05">-5%</wj-menu-item> <wj-menu-item :cmd="command" :cmdParam="-0.10">-10%</wj-menu-item> </wj-menu> </div> </div> </template> <script> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.core'; import '@grapecity/wijmo.vue2.input'; let App = Vue.extend({ name: 'app', data: function(){ return { tax: 0.08, command: { // execute the command executeCommand: (arg) => { arg = wijmo.changeType(arg, wijmo.DataType.Number, null); if (wijmo.isNumber(arg)) { this.tax += arg; } }, // check if a command can be executed canExecuteCommand: (arg) => { arg = wijmo.changeType(arg, wijmo.DataType.Number, null); if (wijmo.isNumber(arg)) { let val = this.tax + arg; return val >= 0 && val <= 1; } return false; } } } } }) let vm = new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> label { width: 120px; text-align: right; margin-right: 3px; } 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 Menu Commands</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>