TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maureen Moore
NA
206
0
Send alert if item has already been selected
Aug 5 2020 6:01 PM
public
onSubmit(id, product_name){
var
data = {
id,
product_name
};
this
.items.push(data);
localStorage.setItem(
this
.storageKey, JSON.stringify(
this
.items));
var
retrieverObject = localStorage.getItem(
'this.items.id'
);
var
retrieveObject = JSON.parse(retrieverObject);
if
(retrieveObject == id) {
alert(
'test'
);
}
}
I want to check if the value has already been submitted. This is part of a shopping cart application in which the product quantity will be updated if the product has already been chosen.
When I use
var
retrieverObject = localStorage.getItem(
'MyDataStorageKey'
);
it returns:
[{
"id"
:0,
"product_name"
:
"Adult Male Bike"
},{
"id"
:0,
"product_name"
:
"Adult Male Bike"
}]
All of the following return null
var
retrieverObject = localStorage.getItem(
'MyDataStorageKey.findIndex(id)'
);
var
retrieverObject = localStorage.getItem(
'MyDataStorageKey.indexOf("id")'
);
var
retrieverObject = localStorage.getItem(
'MyDataStorageKey.indexOf(id)'
);
var
retrieverObject = localStorage.getItem(
'MyDataStorageKey[0].id'
);
var
retrieverObject = localStorage.getItem(
'MyDataStorageKey[0]'
);
var
retrieverObject = localStorage.getItem(
'MyDataStorageKey.findIndex("id")'
);
var
retrieverObject = localStorage.getItem(
'MyDataStorageKey["id"]'
);
var
retrieverObject = localStorage.getItem(
'MyDataStorageKey.id'
);
Reply
Answers (
4
)
ngFor Loop - Display over 2 Bootstrap columns
Cannot read property 'storageKey' of undefined