文字列の書式設定

wijmo.formatメソッドはテンプレート文字列を定義する方法を提供します。それは、慣れ親しんだ方法で文字列と意味のある表現を構築することを可能にします。このサンプルは、formatメソッドを使用してテンプレート文字列内の文字列を置換します。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; // import * as wijmo from '@grapecity/wijmo'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // first example document.querySelector('#btnFormat1').addEventListener('click', () => { let msg = wijmo.format('ようこそ、{name}さん!あなたのポイント数は{miles:n0}です。', { name: '葡萄太郎', miles: 2332123 }); alert(msg); }); // // second example document.querySelector('#btnFormat2').addEventListener('click', () => { let msg = wijmo.format('{name}さんは前回{date:D}に訪問しました。', { name: '葡萄太郎', date: new Date() }); alert(msg); }); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Globalization/Template Strings</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"> <button id="btnFormat1" class="btn btn-default"> 例1の結果を表示 </button> <button id="btnFormat2" class="btn btn-default"> 例2の結果を表示 </button> </div> </body> </html> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.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'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { format1() { let msg = wijmo.format('ようこそ、{name}さん!あなたのポイント数は{miles:n0}です。', { name: '葡萄太郎', miles: 2332123 }); alert(msg); } // format2() { let msg = wijmo.format('{name}さんは前回{date:D}に訪問しました。', { name: '葡萄太郎', date: new Date() }); alert(msg); } } // @NgModule({ imports: [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 Globalization/Template Strings</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"> <button class="btn btn-default" (click)="format1()"> 例1の結果を表示 </button> <button class="btn btn-default" (click)="format2()"> 例2の結果を表示 </button> </div> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as wijmo from "@grapecity/wijmo"; class App extends React.Component { constructor() { super(...arguments); this.format1 = () => { let msg = wijmo.format('ようこそ、{name}さん!あなたのポイント数は{miles:n0}です。', { name: '葡萄太郎', miles: 2332123 }); alert(msg); }; this.format2 = () => { let msg = wijmo.format('{name}さんは前回{date:D}に訪問しました。', { name: '葡萄太郎', date: new Date() }); alert(msg); }; } render() { return <div className="container-fluid"> <button className="btn btn-default" onClick={this.format1}>例1の結果を表示</button> <button className="btn btn-default" onClick={this.format2}>例2の結果を表示</button> </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> <template> <div class="container-fluid"> <button class="btn btn-default" @click="format1">例1の結果を表示</button> <button class="btn btn-default" @click="format2">例2の結果を表示</button> </div> </template> <script> import "bootstrap.css"; import "@grapecity/wijmo.styles/wijmo.css"; import Vue from "vue"; import "@grapecity/wijmo.vue2.nav"; import * as wijmo from "@grapecity/wijmo"; let App = Vue.extend({ name: "app", methods: { format1:function() { let msg = wijmo.format('ようこそ、{name}さん!あなたのポイント数は{miles:n0}です。', { name: '葡萄太郎', miles: 2332123 }); alert(msg); }, format2:function() { let msg = wijmo.format('{name}さんは前回{date:D}に訪問しました。', { name: '葡萄太郎', date: new Date() }); alert(msg); } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Globalization/Template Strings</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>