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

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

Merge pull request !9595 from 葛亚芳/N/A
...@@ -48,10 +48,10 @@ FA模型示例: ...@@ -48,10 +48,10 @@ FA模型示例:
```js ```js
// 获取context // 获取context
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext() let context = featureAbility.getContext();
var preferences = null; let preferences = null;
data_preferences.getPreferences(context, 'mystore', function (err, object) { data_preferences.getPreferences(context, 'mystore', function (err, object) {
if (err) { if (err) {
console.info("Failed to get preferences. Cause: " + err); console.info("Failed to get preferences. Cause: " + err);
...@@ -66,15 +66,15 @@ Stage模型示例: ...@@ -66,15 +66,15 @@ Stage模型示例:
```ts ```ts
// 获取context // 获取context
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability';
var context; let context = null;
class MainAbility extends Ability{ class MainAbility extends Ability{
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context context = this.context;
} }
} }
var preferences = null; let preferences = null;
data_preferences.getPreferences(context, 'mystore', function (err, object) { data_preferences.getPreferences(context, 'mystore', function (err, object) {
if (err) { if (err) {
console.info("Failed to get preferences. Cause: " + err); console.info("Failed to get preferences. Cause: " + err);
...@@ -112,11 +112,11 @@ FA模型示例: ...@@ -112,11 +112,11 @@ FA模型示例:
```js ```js
// 获取context // 获取context
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext() let context = featureAbility.getContext();
var preferences = null; let preferences = null;
let promise = data_preferences.getPreferences(context, 'mystore') let promise = data_preferences.getPreferences(context, 'mystore');
promise.then((object) => { promise.then((object) => {
preferences = object; preferences = object;
console.info("Succeeded in getting preferences."); console.info("Succeeded in getting preferences.");
...@@ -129,16 +129,16 @@ Stage模型示例: ...@@ -129,16 +129,16 @@ Stage模型示例:
```ts ```ts
// 获取context // 获取context
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability';
var context; let context = null;
class MainAbility extends Ability{ class MainAbility extends Ability{
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context context = this.context;
} }
} }
var preferences = null; let preferences = null;
let promise = data_preferences.getPreferences(context, 'mystore') let promise = data_preferences.getPreferences(context, 'mystore');
promise.then((object) => { promise.then((object) => {
preferences = object; preferences = object;
console.info("Succeeded in getting preferences."); console.info("Succeeded in getting preferences.");
...@@ -173,13 +173,13 @@ FA模型示例: ...@@ -173,13 +173,13 @@ FA模型示例:
```js ```js
// 获取context // 获取context
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext() let context = featureAbility.getContext();
data_preferences.deletePreferences(context, 'mystore', function (err) { data_preferences.deletePreferences(context, 'mystore', function (err) {
if (err) { if (err) {
console.info("Failed to delete preferences. Cause: " + err); console.info("Failed to delete preferences. Cause: " + err);
return return;
} }
console.info("Succeeded in deleting preferences." ); console.info("Succeeded in deleting preferences." );
}) })
...@@ -189,18 +189,18 @@ Stage模型示例: ...@@ -189,18 +189,18 @@ Stage模型示例:
```ts ```ts
// 获取context // 获取context
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability';
var context let context = null;
class MainAbility extends Ability{ class MainAbility extends Ability{
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context context = this.context;
} }
} }
data_preferences.deletePreferences(context, 'mystore', function (err) { data_preferences.deletePreferences(context, 'mystore', function (err) {
if (err) { if (err) {
console.info("Failed to delete preferences. Cause: " + err); console.info("Failed to delete preferences. Cause: " + err);
return return;
} }
console.info("Succeeded in deleting preferences." ); console.info("Succeeded in deleting preferences." );
}) })
...@@ -237,10 +237,10 @@ FA模型示例: ...@@ -237,10 +237,10 @@ FA模型示例:
```js ```js
// 获取context // 获取context
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext() let context = featureAbility.getContext();
let promise = data_preferences.deletePreferences(context, 'mystore') let promise = data_preferences.deletePreferences(context, 'mystore');
promise.then(() => { promise.then(() => {
console.info("Succeeded in deleting preferences."); console.info("Succeeded in deleting preferences.");
}).catch((err) => { }).catch((err) => {
...@@ -252,15 +252,15 @@ Stage模型示例: ...@@ -252,15 +252,15 @@ Stage模型示例:
```ts ```ts
// 获取context // 获取context
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability';
var context let context = null;
class MainAbility extends Ability{ class MainAbility extends Ability{
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context context = this.context;
} }
} }
let promise = data_preferences.deletePreferences(context, 'mystore') let promise = data_preferences.deletePreferences(context, 'mystore');
promise.then(() => { promise.then(() => {
console.info("Succeeded in deleting preferences."); console.info("Succeeded in deleting preferences.");
}).catch((err) => { }).catch((err) => {
...@@ -292,8 +292,8 @@ FA模型示例: ...@@ -292,8 +292,8 @@ FA模型示例:
```js ```js
// 获取context // 获取context
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext() let context = featureAbility.getContext();
data_preferences.removePreferencesFromCache(context, 'mystore', function (err) { data_preferences.removePreferencesFromCache(context, 'mystore', function (err) {
if (err) { if (err) {
...@@ -308,11 +308,11 @@ Stage模型示例: ...@@ -308,11 +308,11 @@ Stage模型示例:
```ts ```ts
// 获取context // 获取context
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability';
var context let context = null;
class MainAbility extends Ability{ class MainAbility extends Ability{
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context context = this.context;
} }
} }
...@@ -354,10 +354,10 @@ FA模型示例: ...@@ -354,10 +354,10 @@ FA模型示例:
```js ```js
// 获取context // 获取context
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext() let context = featureAbility.getContext();
let promise = data_preferences.removePreferencesFromCache(context, 'mystore') let promise = data_preferences.removePreferencesFromCache(context, 'mystore');
promise.then(() => { promise.then(() => {
console.info("Succeeded in removing preferences."); console.info("Succeeded in removing preferences.");
}).catch((err) => { }).catch((err) => {
...@@ -369,15 +369,15 @@ Stage模型示例: ...@@ -369,15 +369,15 @@ Stage模型示例:
```ts ```ts
// 获取context // 获取context
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability';
var context let context = null;
class MainAbility extends Ability{ class MainAbility extends Ability{
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context context = this.context;
} }
} }
let promise = data_preferences.removePreferencesFromCache(context, 'mystore') let promise = data_preferences.removePreferencesFromCache(context, 'mystore');
promise.then(() => { promise.then(() => {
console.info("Succeeded in removing preferences."); console.info("Succeeded in removing preferences.");
}).catch((err) => { }).catch((err) => {
...@@ -828,11 +828,11 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, preferen ...@@ -828,11 +828,11 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, preferen
console.info("Failed to get preferences."); console.info("Failed to get preferences.");
return; return;
} }
var observer = function (key) { let observer = function (key) {
console.info("The key " + key + " changed."); console.info("The key " + key + " changed.");
} }
preferences.on('change', observer); preferences.on('change', observer);
preferences.put('startup', 'auto', function (err) { preferences.put('startup', 'manual', function (err) {
if (err) { if (err) {
console.info("Failed to put the value of 'startup'. Cause: " + err); console.info("Failed to put the value of 'startup'. Cause: " + err);
return; return;
...@@ -874,7 +874,7 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, preferen ...@@ -874,7 +874,7 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, preferen
console.info("Failed to get preferences."); console.info("Failed to get preferences.");
return; return;
} }
var observer = function (key) { let observer = function (key) {
console.info("The key " + key + " changed."); console.info("The key " + key + " changed.");
} }
preferences.on('change', observer); preferences.on('change', observer);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册