w2toolbar.add
更新日: 2018-09-07
add(items)
アイテムを追加します。 戻り値はundefinedです。
- items: object, array
- 追加するアイテム
説明
引数には、オブジェクトまたは、オブジェクトの配列を指定することができます。 単一のオブジェクトの場合、.items配列に追加するアイテムを表します。 オブジェクト配列の場合、配列の各要素は別々のアイテム要素として扱います。
ツールバーが以下のように定義されている場合、
$('#toolbar').w2toolbar({
    name  : 'toolbar',
    items : [
        { type: 'check',  id: 'item1', text: 'Check', img: 'icon-page', checked: true },
        { type: 'radio',  id: 'item3',  group: '1', text: 'Radio 1', img: 'icon-add' },
        { type: 'radio',  id: 'item4',  group: '1', text: 'Radio 2', img: 'icon-add' }
    ]
});以下のようにアイテムを追加することができます。
w2ui['toolbar'].add({ type: 'radio',  id: 'item31',  group: '1', text: 'Radio 3', img: 'icon-add' });
// または
w2ui['toolbar'].add([
    { type: 'radio',  id: 'item5',  group: '1', text: 'Radio 5', img: 'icon-add' },
    { type: 'radio',  id: 'item6',  group: '1', text: 'Radio 6', img: 'icon-add' },
    { type: 'radio',  id: 'item7',  group: '1', text: 'Radio 7', img: 'icon-add' }
]);デモ
ボタンをクリックすると、新しいアイテムが追加されます。
JavaScript
$('#toolbar').w2toolbar({
  name  : 'mytoolbar',
  items : [
    { type: 'button',  id: 'item1', text: 'button' },
  ],
});
$('#get-result').on('click', function(){
  w2ui['mytoolbar'].add([
    { type: 'radio',  id: 'item5',  group: '1', text: 'Radio 1', img: 'icon-add' },
    { type: 'radio',  id: 'item6',  group: '1', text: 'Radio 2', img: 'icon-add' },
  ]);
});HTML
<button id="get-result">実行</button>
<div id="toolbar"></div>© 2017.  .
.
Code licensed under theMIT License. Documentation licensed underCC BY 3.0.
このコンテンツはvitmalinaによるw2ui.toolbarドキュメントを翻訳/改変したものです。