w2toolbar.disable
更新日: 2018-09-07
disable(id1, [id2], ...)
idを指定してアイテムを無効化します。 戻り値はintegerです。
- id: string
- 無効化するアイテムのid。
説明
ツールバーに.items配列が存在していなければなりません。 ツールバーアイテムは.idプロパティで識別されます。 このメソッドは、元々有効だった*1アイテムが無効化された場合に、その個数を返します。
*1 "元々有効"かどうかは判定しておらず、指定したアイテムの個数を返すようです。
ツールバーが以下のように定義されている場合、
$('#toolbar').w2toolbar({
    name  : 'toolbar',
    items : [
        { type: 'check',  id: 'item1', text: 'Check', img: 'icon-page', checked: true },
        { type: 'radio',  id: 'item3',  group: '1', text: 'R-1', img: 'icon-add', disabled: true },
        { type: 'radio',  id: 'item4',  group: '1', text: 'R-2', img: 'icon-add' },
        { type: 'menu',   id: 'item5', text: 'Drop Down',
            items: [
                { id: 'id1', text: 'menu 1' },
                { id: 'id2', text: 'menu 2' },
                { id: 'id3', text: 'menu 3' },
            ]
        }
    ]
});以下のように指定します。
w2ui['toolbar'].disable('item3', 'item4');メニューのアイテムを無効化することもできます。
w2ui['toolbar'].disable('item5:id2', 'item5:id3');デモ
ボタンをクリックすると、'check1'と'check3'を無効化します。
JavaScript
$('#toolbar').w2toolbar({
  name  : 'mytoolbar',
  items : [
    { type: 'check',  id: 'item1', text: 'check1' },
    { type: 'check',  id: 'item2', text: 'check2' },
    { type: 'check',  id: 'item3', text: 'check3', disabled: true },
  ],
});
$('#get-result').on('click', function(){
  var result = w2ui['mytoolbar'].disable('item1', 'item3');
  document.getElementById('result').innerHTML = result + '個を無効化';
});HTML
<button id="get-result">実行</button>
<div>
  <span id="result"></span>
</div>
<div id="toolbar"></div>© 2017.  .
.
Code licensed under theMIT License. Documentation licensed underCC BY 3.0.
このコンテンツはvitmalinaによるw2ui.toolbarドキュメントを翻訳/改変したものです。