This API is available on Firefox OS for internal applications 仅。

摘要

Sets up a callback function to be notified when a specific setting's value changes.

注意: If you want to listen for and react to any change to any setting, you can directly set a callback function using the onsettingchange 特性为 SettingsManager 对象。

句法

SettingsManager.addObserver(settingName, callback);
					

参数

settingName
A string specifying the name of the setting to observe. The exact list of possible strings is device-dependent. Each Gaia build can have its own list of settings. For an up-to-date list of those strings, take a look at the Gaia source code .
callback
The function to be called each time the value of the setting is changed. This function will receive as input a MozSettingsEvent providing details about the change that occurred.

范例

// Listen to changes on the wifi.enabled setting
navigator.mozSettings.addObserver('wifi.enabled', function (event) {
  console.log('wifi.enabled: ' + event.settingValue);
});
					

规范

Not part of any specification yet; however, this API will be discussed at W3C as part of the System Applications Working Group .

另请参阅

元数据

  • 最后修改: