本文整理匯總了TypeScript中@ionic-native/native-storage.NativeStorage.setItem方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript NativeStorage.setItem方法的具體用法?TypeScript NativeStorage.setItem怎麽用?TypeScript NativeStorage.setItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ionic-native/native-storage.NativeStorage
的用法示例。
在下文中一共展示了NativeStorage.setItem方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
this.serverProvider.post(this.storageProvider.serverAddress+"/preventMultiLogin",body).then((res:any)=>{
console.log("res:"+JSON.stringify(res));
if(res.result=="success"){
// move into TabPage
if(res.userInfo.hasOwnProperty("shopList")){
this.storageProvider.shoplistSet(JSON.parse(res.userInfo.shopList));
}
//save this.storageProvider.id
this.storageProvider.userInfoSetFromServer(res.userInfo);
//save id information into storage
let id=this.navParams.get("id");
if(id!=undefined){
var encrypted:string=this.storageProvider.encryptValue('id',id);
this.nativeStorage.setItem('id',encodeURI(encrypted));
this.storageProvider.id=id;
}else{
//read id info and then save it into storageProvider
this.nativeStorage.getItem("id").then((value:string)=>{
this.storageProvider.id=this.storageProvider.decryptValue("id",decodeURI(value));
});
}
console.log("move into TbasPage");
this.app.getRootNav().setRoot(TabsPage);
}else{
console.log("move into LoginPage");
// move into loginPage
this.storageProvider.reset();
this.app.getRootNav().setRoot(LoginPage);
}
});
示例2: if
this.serverSecretSubmit().then((res:any)=>{
console.log("secretSubmit "+JSON.stringify(res));
if(res.result=="success"){
if(this.id.startsWith("facebook_")){
var encrypted:string=this.storageProvider.encryptValue('id','facebook');
this.nativeStorage.setItem('id',encodeURI(encrypted));
}else if(this.id.startsWith("kakao_")){
var encrypted:string=this.storageProvider.encryptValue('id','kakao');
this.nativeStorage.setItem('id',encodeURI(encrypted));
}
this.shoplistHandler(res.shopUserInfo);
}else if(res.result=='invalidId'){
console.log("You have no right to access this app");
//this.storageProvider.errorReasonSet('접근권한이 없습니다.');
this.navController.setRoot(ErrorPage);
}else{
console.log("invalid result comes from server-"+JSON.stringify(res));
//this.storageProvider.errorReasonSet('서버로 부터 알수 없는 응답을 받았습니다.');
this.navController.setRoot(ErrorPage);
}
},(err)=>{
示例3: Promise
return new Promise((resolve,reject)=>{
let headers = new Headers();
headers.append('Content-Type', 'application/json');
console.log("saveOrder:"+body);
this.post(encodeURI(this.storageProvider.serverAddress+"/saveOrder"),body).then((res:any)=>{
console.log("res:"+JSON.stringify(res));
console.log("saveOrder-res.result:"+res.result);
if(res.result=="success"){
//resolve(res.orders);
resolve(res);
}else{
reject(res.error);
}
},(err)=>{
reject(err);
});
this.nativeStorage.setItem("orderDoneFlag","true");
});
示例4:
this.nativeStorage.getItem(username).then((user)=>{
user.favorites=this.favorites;
this.nativeStorage.setItem(user.username,user).then(()=>{
console.log("deleted favorite")
},error=>{console.error("error en set item")})
})