未验证 提交 5e67f663 编写于 作者: O openharmony_ci 提交者: Gitee

!22305 【轻量级 PR】:update zh-cn/application-dev/reference/apis/js-apis-data-preferences.md.

Merge pull request !22305 from 葛亚芳/N/A
...@@ -55,14 +55,14 @@ let preferences = null; ...@@ -55,14 +55,14 @@ let preferences = null;
try { try {
data_preferences.getPreferences(context, 'mystore', function (err, val) { data_preferences.getPreferences(context, 'mystore', function (err, val) {
if (err) { if (err) {
console.info("Failed to get preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to get preferences. code =" + err.code + ", message =" + err.message);
return; return;
} }
preferences = val; preferences = val;
console.info("Succeeded in getting preferences."); console.info("Succeeded in getting preferences.");
}) })
} catch (err) { } catch (err) {
console.info("Failed to get preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to get preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -78,14 +78,14 @@ class EntryAbility extends UIAbility { ...@@ -78,14 +78,14 @@ class EntryAbility extends UIAbility {
try { try {
data_preferences.getPreferences(this.context, 'mystore', function (err, val) { data_preferences.getPreferences(this.context, 'mystore', function (err, val) {
if (err) { if (err) {
console.info("Failed to get preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to get preferences. code =" + err.code + ", message =" + err.message);
return; return;
} }
preferences = val; preferences = val;
console.info("Succeeded in getting preferences."); console.info("Succeeded in getting preferences.");
}) })
} catch (err) { } catch (err) {
console.info("Failed to get preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to get preferences. code =" + err.code + ", message =" + err.message);
} }
} }
} }
...@@ -128,10 +128,10 @@ try { ...@@ -128,10 +128,10 @@ try {
preferences = object; preferences = object;
console.info("Succeeded in getting preferences."); console.info("Succeeded in getting preferences.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to get preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to get preferences. code =" + err.code + ", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.info("Failed to get preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to get preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -150,10 +150,10 @@ class EntryAbility extends UIAbility { ...@@ -150,10 +150,10 @@ class EntryAbility extends UIAbility {
preferences = object; preferences = object;
console.info("Succeeded in getting preferences."); console.info("Succeeded in getting preferences.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to get preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to get preferences. code =" + err.code + ", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.info("Failed to get preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to get preferences. code =" + err.code + ", message =" + err.message);
} }
} }
} }
...@@ -199,13 +199,13 @@ let context = featureAbility.getContext(); ...@@ -199,13 +199,13 @@ let context = featureAbility.getContext();
try { try {
data_preferences.deletePreferences(context, 'mystore', function (err) { data_preferences.deletePreferences(context, 'mystore', function (err) {
if (err) { if (err) {
console.info("Failed to delete preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to delete preferences. code =" + err.code + ", message =" + err.message);
return; return;
} }
console.info("Succeeded in deleting preferences." ); console.info("Succeeded in deleting preferences." );
}) })
} catch (err) { } catch (err) {
console.info("Failed to delete preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to delete preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -218,13 +218,13 @@ class EntryAbility extends UIAbility { ...@@ -218,13 +218,13 @@ class EntryAbility extends UIAbility {
try { try {
data_preferences.deletePreferences(this.context, 'mystore', function (err) { data_preferences.deletePreferences(this.context, 'mystore', function (err) {
if (err) { if (err) {
console.info("Failed to delete preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to delete preferences. code =" + err.code + ", message =" + err.message);
return; return;
} }
console.info("Succeeded in deleting preferences." ); console.info("Succeeded in deleting preferences." );
}) })
} catch (err) { } catch (err) {
console.info("Failed to delete preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to delete preferences. code =" + err.code + ", message =" + err.message);
} }
} }
} }
...@@ -277,10 +277,10 @@ try { ...@@ -277,10 +277,10 @@ try {
promise.then(() => { promise.then(() => {
console.info("Succeeded in deleting preferences."); console.info("Succeeded in deleting preferences.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to delete preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to delete preferences. code =" + err.code + ", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.info("Failed to delete preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to delete preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -295,10 +295,10 @@ class EntryAbility extends UIAbility { ...@@ -295,10 +295,10 @@ class EntryAbility extends UIAbility {
promise.then(() => { promise.then(() => {
console.info("Succeeded in deleting preferences."); console.info("Succeeded in deleting preferences.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to delete preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to delete preferences. code =" + err.code + ", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.info("Failed to delete preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to delete preferences. code =" + err.code + ", message =" + err.message);
} }
} }
} }
...@@ -334,13 +334,13 @@ let context = featureAbility.getContext(); ...@@ -334,13 +334,13 @@ let context = featureAbility.getContext();
try { try {
data_preferences.removePreferencesFromCache(context, 'mystore', function (err) { data_preferences.removePreferencesFromCache(context, 'mystore', function (err) {
if (err) { if (err) {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
return; return;
} }
console.info("Succeeded in removing preferences."); console.info("Succeeded in removing preferences.");
}) })
} catch (err) { } catch (err) {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -353,13 +353,13 @@ class EntryAbility extends UIAbility { ...@@ -353,13 +353,13 @@ class EntryAbility extends UIAbility {
try { try {
data_preferences.removePreferencesFromCache(this.context, 'mystore', function (err) { data_preferences.removePreferencesFromCache(this.context, 'mystore', function (err) {
if (err) { if (err) {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
return; return;
} }
console.info("Succeeded in removing preferences."); console.info("Succeeded in removing preferences.");
}) })
} catch (err) { } catch (err) {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
} }
} }
} }
...@@ -403,10 +403,10 @@ try { ...@@ -403,10 +403,10 @@ try {
promise.then(() => { promise.then(() => {
console.info("Succeeded in removing preferences."); console.info("Succeeded in removing preferences.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -422,10 +422,10 @@ class EntryAbility extends UIAbility { ...@@ -422,10 +422,10 @@ class EntryAbility extends UIAbility {
promise.then(() => { promise.then(() => {
console.info("Succeeded in removing preferences."); console.info("Succeeded in removing preferences.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.info("Failed to remove preferences. code =" + err.code + ", message =" + err.message); console.error("Failed to remove preferences. code =" + err.code + ", message =" + err.message);
} }
} }
} }
...@@ -460,13 +460,13 @@ get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>): ...@@ -460,13 +460,13 @@ get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>):
try { try {
preferences.get('startup', 'default', function (err, val) { preferences.get('startup', 'default', function (err, val) {
if (err) { if (err) {
console.info("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message); console.error("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message);
return; return;
} }
console.info("Succeeded in getting value of 'startup'. val: " + val); console.info("Succeeded in getting value of 'startup'. val: " + val);
}) })
} catch (err) { } catch (err) {
console.info("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message); console.error("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -500,10 +500,10 @@ try { ...@@ -500,10 +500,10 @@ try {
promise.then((data) => { promise.then((data) => {
console.info("Succeeded in getting value of 'startup'. Data: " + data); console.info("Succeeded in getting value of 'startup'. Data: " + data);
}).catch((err) => { }).catch((err) => {
console.info("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message); console.error("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.info("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message); console.error("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -527,7 +527,7 @@ getAll(callback: AsyncCallback<Object>): void; ...@@ -527,7 +527,7 @@ getAll(callback: AsyncCallback<Object>): void;
try { try {
preferences.getAll(function (err, value) { preferences.getAll(function (err, value) {
if (err) { if (err) {
console.info("Failed to get all key-values. code =" + err.code + ", message =" + err.message); console.error("Failed to get all key-values. code =" + err.code + ", message =" + err.message);
return; return;
} }
let allKeys = Object.keys(value); let allKeys = Object.keys(value);
...@@ -535,7 +535,7 @@ try { ...@@ -535,7 +535,7 @@ try {
console.info("getAll object = " + JSON.stringify(value)); console.info("getAll object = " + JSON.stringify(value));
}) })
} catch (err) { } catch (err) {
console.info("Failed to get all key-values. code =" + err.code + ", message =" + err.message); console.error("Failed to get all key-values. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -564,10 +564,10 @@ try { ...@@ -564,10 +564,10 @@ try {
console.info('getAll keys = ' + allKeys); console.info('getAll keys = ' + allKeys);
console.info("getAll object = " + JSON.stringify(value)); console.info("getAll object = " + JSON.stringify(value));
}).catch((err) => { }).catch((err) => {
console.info("Failed to get all key-values. code =" + err.code + ", message =" + err.message); console.error("Failed to get all key-values. code =" + err.code + ", message =" + err.message);
}) })
} catch (err) { } catch (err) {
console.info("Failed to get all key-values. code =" + err.code + ", message =" + err.message); console.error("Failed to get all key-values. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -593,13 +593,13 @@ put(key: string, value: ValueType, callback: AsyncCallback<void>): void ...@@ -593,13 +593,13 @@ put(key: string, value: ValueType, callback: AsyncCallback<void>): void
try { try {
preferences.put('startup', 'auto', function (err) { preferences.put('startup', 'auto', function (err) {
if (err) { if (err) {
console.info("Failed to put value of 'startup'. code =" + err.code + ", message =" + err.message); console.error("Failed to put value of 'startup'. code =" + err.code + ", message =" + err.message);
return; return;
} }
console.info("Succeeded in putting value of 'startup'."); console.info("Succeeded in putting value of 'startup'.");
}) })
} catch (err) { } catch (err) {
console.info("Failed to put value of 'startup'. code =" + err.code + ", message =" + err.message); console.error("Failed to put value of 'startup'. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -633,10 +633,10 @@ try { ...@@ -633,10 +633,10 @@ try {
promise.then(() => { promise.then(() => {
console.info("Succeeded in putting value of 'startup'."); console.info("Succeeded in putting value of 'startup'.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to put value of 'startup'. code =" + err.code +", message =" + err.message); console.error("Failed to put value of 'startup'. code =" + err.code +", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.info("Failed to put value of 'startup'. code =" + err.code +", message =" + err.message); console.error("Failed to put value of 'startup'. code =" + err.code +", message =" + err.message);
} }
``` ```
...@@ -662,7 +662,7 @@ has(key: string, callback: AsyncCallback<boolean>): void ...@@ -662,7 +662,7 @@ has(key: string, callback: AsyncCallback<boolean>): void
try { try {
preferences.has('startup', function (err, val) { preferences.has('startup', function (err, val) {
if (err) { if (err) {
console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message); console.error("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
return; return;
} }
if (val) { if (val) {
...@@ -672,7 +672,7 @@ try { ...@@ -672,7 +672,7 @@ try {
} }
}) })
} catch (err) { } catch (err) {
console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message); console.error("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -709,10 +709,10 @@ try { ...@@ -709,10 +709,10 @@ try {
console.info("The key 'startup' dose not contain."); console.info("The key 'startup' dose not contain.");
} }
}).catch((err) => { }).catch((err) => {
console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message); console.error("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message); console.error("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -738,13 +738,13 @@ delete(key: string, callback: AsyncCallback<void>): void ...@@ -738,13 +738,13 @@ delete(key: string, callback: AsyncCallback<void>): void
try { try {
preferences.delete('startup', function (err) { preferences.delete('startup', function (err) {
if (err) { if (err) {
console.info("Failed to delete the key 'startup'. code =" + err.code + ", message =" + err.message); console.error("Failed to delete the key 'startup'. code =" + err.code + ", message =" + err.message);
return; return;
} }
console.info("Succeeded in deleting the key 'startup'."); console.info("Succeeded in deleting the key 'startup'.");
}) })
} catch (err) { } catch (err) {
console.info("Failed to delete the key 'startup'. code =" + err.code + ", message =" + err.message); console.error("Failed to delete the key 'startup'. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -777,10 +777,10 @@ try { ...@@ -777,10 +777,10 @@ try {
promise.then(() => { promise.then(() => {
console.info("Succeeded in deleting the key 'startup'."); console.info("Succeeded in deleting the key 'startup'.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message); console.error("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.info("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message); console.error("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message);
} }
``` ```
...@@ -805,13 +805,13 @@ flush(callback: AsyncCallback<void>): void ...@@ -805,13 +805,13 @@ flush(callback: AsyncCallback<void>): void
try { try {
preferences.flush(function (err) { preferences.flush(function (err) {
if (err) { if (err) {
console.info("Failed to flush. code =" + err.code + ", message =" + err.message); console.error("Failed to flush. code =" + err.code + ", message =" + err.message);
return; return;
} }
console.info("Succeeded in flushing."); console.info("Succeeded in flushing.");
}) })
} catch (err) { } catch (err) {
console.info("Failed to flush. code =" + err.code + ", message =" + err.message); console.error("Failed to flush. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -838,10 +838,10 @@ try { ...@@ -838,10 +838,10 @@ try {
promise.then(() => { promise.then(() => {
console.info("Succeeded in flushing."); console.info("Succeeded in flushing.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to flush. code =" + err.code + ", message =" + err.message); console.error("Failed to flush. code =" + err.code + ", message =" + err.message);
}) })
} catch (err) { } catch (err) {
console.info("Failed to flush. code =" + err.code + ", message =" + err.message); console.error("Failed to flush. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -866,13 +866,13 @@ clear(callback: AsyncCallback<void>): void ...@@ -866,13 +866,13 @@ clear(callback: AsyncCallback<void>): void
try { try {
preferences.clear(function (err) { preferences.clear(function (err) {
if (err) { if (err) {
console.info("Failed to clear. code =" + err.code + ", message =" + err.message); console.error("Failed to clear. code =" + err.code + ", message =" + err.message);
return; return;
} }
console.info("Succeeded in clearing."); console.info("Succeeded in clearing.");
}) })
} catch (err) { } catch (err) {
console.info("Failed to clear. code =" + err.code + ", message =" + err.message); console.error("Failed to clear. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -899,10 +899,10 @@ try { ...@@ -899,10 +899,10 @@ try {
promise.then(() => { promise.then(() => {
console.info("Succeeded in clearing."); console.info("Succeeded in clearing.");
}).catch((err) => { }).catch((err) => {
console.info("Failed to clear. code =" + err.code + ", message =" + err.message); console.error("Failed to clear. code =" + err.code + ", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.info("Failed to clear. code =" + err.code + ", message =" + err.message); console.error("Failed to clear. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -928,7 +928,7 @@ on(type: 'change', callback: Callback<{ key : string }>): void ...@@ -928,7 +928,7 @@ on(type: 'change', callback: Callback<{ key : string }>): void
try { try {
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) { data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
if (err) { if (err) {
console.info("Failed to get preferences."); console.error("Failed to get preferences.");
return; return;
} }
let observer = function (key) { let observer = function (key) {
...@@ -937,14 +937,14 @@ try { ...@@ -937,14 +937,14 @@ try {
preferences.on('change', observer); preferences.on('change', observer);
preferences.put('startup', 'manual', function (err) { preferences.put('startup', 'manual', function (err) {
if (err) { if (err) {
console.info("Failed to put the value of 'startup'. Cause: " + err); console.error("Failed to put the value of 'startup'. Cause: " + err);
return; return;
} }
console.info("Succeeded in putting the value of 'startup'."); console.info("Succeeded in putting the value of 'startup'.");
preferences.flush(function (err) { preferences.flush(function (err) {
if (err) { if (err) {
console.info("Failed to flush. Cause: " + err); console.error("Failed to flush. Cause: " + err);
return; return;
} }
console.info("Succeeded in flushing."); console.info("Succeeded in flushing.");
...@@ -952,7 +952,7 @@ try { ...@@ -952,7 +952,7 @@ try {
}) })
}) })
} catch (err) { } catch (err) {
console.info("Failed to flush. code =" + err.code + ", message =" + err.message); console.error("Failed to flush. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -978,7 +978,7 @@ off(type: 'change', callback?: Callback<{ key : string }>): void ...@@ -978,7 +978,7 @@ off(type: 'change', callback?: Callback<{ key : string }>): void
try { try {
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) { data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
if (err) { if (err) {
console.info("Failed to get preferences."); console.error("Failed to get preferences.");
return; return;
} }
let observer = function (key) { let observer = function (key) {
...@@ -987,14 +987,14 @@ try { ...@@ -987,14 +987,14 @@ try {
preferences.on('change', observer); preferences.on('change', observer);
preferences.put('startup', 'auto', function (err) { preferences.put('startup', 'auto', function (err) {
if (err) { if (err) {
console.info("Failed to put the value of 'startup'. Cause: " + err); console.error("Failed to put the value of 'startup'. Cause: " + err);
return; return;
} }
console.info("Succeeded in putting the value of 'startup'."); console.info("Succeeded in putting the value of 'startup'.");
preferences.flush(function (err) { preferences.flush(function (err) {
if (err) { if (err) {
console.info("Failed to flush. Cause: " + err); console.error("Failed to flush. Cause: " + err);
return; return;
} }
console.info("Succeeded in flushing."); console.info("Succeeded in flushing.");
...@@ -1003,7 +1003,7 @@ try { ...@@ -1003,7 +1003,7 @@ try {
}) })
}) })
} catch (err) { } catch (err) {
console.info("Failed to flush. code =" + err.code + ", message =" + err.message); console.error("Failed to flush. code =" + err.code + ", message =" + err.message);
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册