{hero}

buttons.buttons.namespace

自:Buttons 3.0.0 起

每個按鈕的唯一命名空間。
請注意 - 此屬性需要 DataTables 的 Buttons 擴充功能。

說明

當使用 buttons.buttons.init 選項在頁面上觸發動作時,作者能夠為按鈕或 DataTable 添加事件通常很有用。為了能夠乾淨地移除附加的事件,並防止這些事件監聽器可能造成的記憶體洩漏,Buttons 會自動為每個按鈕生成一個命名空間字串。buttons.buttons.destroy 選項可以用來定義一個將移除已添加事件監聽器的函式。

可以定義自己的命名空間,但 強烈 建議您不要提供自訂值,而是讓 Buttons 指定其自己的值。指定自己的命名空間沒有任何好處!

此參數的記錄主要是為了讓您知道它存在,並且是由 Buttons 自動生成的。

類型

字串

說明

如果給定,這個字串對於在頁面上創建的每個按鈕都應該是唯一的,並帶有一個句點(.)。然而,強烈建議您不要設置此參數 - 讓 Buttons 指定一個唯一的值。

預設值

  • 值:null

預設值由 Buttons 自動指定

範例

具有滑鼠進入/離開(懸停)事件監聽器的按鈕

new DataTable('#myTable', {
	layout: {
		topEnd: {
			buttons: [
				{
					text: '',
					init: function (e, dt, node, config) {
						node.on('mouseenter' + config.namespace, function () {
							console.log('Mouse enter');
						});

						node.on('mouseleave' + config.namespace, function () {
							console.log('Mouse leave');
						});
					},
					destroy: function (dt, node, config) {
						node.off('mouseenter' + config.namespace);
						node.off('mouseleave' + config.namespace);
					}
				}
			]
		}
	}
});