Baseline Widely available
error
ãã³ãã©ã¼ã¯ãã¨ã©ã¼ã«ãã£ã¦è¦æ±ã失æããã¨ãå®è¡ããã¾ãã
ãã®ã¤ãã³ãã¯ãã£ã³ã»ã«ã§ããããããªã³ã°ãã¾ããã
æ§æaddEventListener()
ã®ãããªã¡ã½ããã§ã¤ãã³ãåã使ãããã¤ãã³ããã³ãã©ã¼ããããã£ãè¨å®ãã¾ãã
addEventListener("error", (event) => {});
onerror = (event) => {};
ã¤ãã³ãå
æ±ç¨ã® Event
ã§ãã
ãã®ä¾ã§ã¯ããã¼ã¿ãã¼ã¹ãéããadd()
æä½ã§ã® error
ã¤ãã³ããç£è¦ããªãããã¬ã³ã¼ãã追å ãããã¨ãã¾ãã(ä¾ãã°ãæå®ã® taskTitle
ãæã¤ã¬ã³ã¼ããæ¢ã«åå¨ããå ´åã¨ã©ã¼ãçºçãã¾ã)
// ãã¼ã¿ãã¼ã¹ãéãã¾ã
const DBOpenRequest = window.indexedDB.open("toDoList", 4);
DBOpenRequest.addEventListener("upgradeneeded", (event) => {
const db = event.target.result;
db.onerror = () => {
console.log("ãã¼ã¿ãã¼ã¹ã®ä½æä¸ã«ã¨ã©ã¼ãçºçãã¾ãã");
};
// ãã®ãã¼ã¿ãã¼ã¹ç¨ã® objectStore ã使ãã¾ã
const objectStore = db.createObjectStore("toDoList", {
keyPath: "taskTitle",
});
// objectStore ã«ä¿åãããã¼ã¿ã¢ã¤ãã ãå®ç¾©ãã¾ã
objectStore.createIndex("hours", "hours", { unique: false });
objectStore.createIndex("minutes", "minutes", { unique: false });
objectStore.createIndex("day", "day", { unique: false });
objectStore.createIndex("month", "month", { unique: false });
objectStore.createIndex("year", "year", { unique: false });
});
DBOpenRequest.addEventListener("success", (event) => {
const db = DBOpenRequest.result;
// èªã¿æ¸ãç¨ã®ãã¼ã¿ãã¼ã¹ãã©ã³ã¶ã¯ã·ã§ã³ãéãããã¼ã¿ã追å ããæºåããã¾ã
const transaction = db.transaction(["toDoList"], "readwrite");
const objectStore = transaction.objectStore("toDoList");
const newItem = {
taskTitle: "my task",
hours: 10,
minutes: 10,
day: 10,
month: "January",
year: 2020,
};
const objectStoreRequest = objectStore.add(newItem);
objectStoreRequest.addEventListener("error", () => {
console.log(
`æ°è¦ã¢ã¤ãã ã®è¿½å ä¸ã«ã¨ã©ã¼ãçºçãã¾ãã: ${newItem.taskTitle}`,
);
});
});
åãä¾ã§ãaddEventListener()
ã®ãããã« onerror
ããããã£ã使ç¨ãã¾ãã
// ãã¼ã¿ãã¼ã¹ãéãã¾ã
const DBOpenRequest = window.indexedDB.open("toDoList", 4);
DBOpenRequest.onupgradeneeded = (event) => {
const db = event.target.result;
db.onerror = () => {
console.log("ãã¼ã¿ãã¼ã¹ã®ä½æä¸ã«ã¨ã©ã¼ãçºçãã¾ãã");
};
// ãã®ãã¼ã¿ãã¼ã¹ç¨ã® objectStore ã使ãã¾ã
const objectStore = db.createObjectStore("toDoList", {
keyPath: "taskTitle",
});
// objectStore ã«ä¿åãããã¼ã¿ã¢ã¤ãã ãå®ç¾©ãã¾ã
objectStore.createIndex("hours", "hours", { unique: false });
objectStore.createIndex("minutes", "minutes", { unique: false });
objectStore.createIndex("day", "day", { unique: false });
objectStore.createIndex("month", "month", { unique: false });
objectStore.createIndex("year", "year", { unique: false });
};
DBOpenRequest.onsuccess = (event) => {
const db = DBOpenRequest.result;
// èªã¿æ¸ãç¨ã®ãã¼ã¿ãã¼ã¹ãã©ã³ã¶ã¯ã·ã§ã³ãéã、ãã¼ã¿ã追å ããæºåããã¾ã
const transaction = db.transaction(["toDoList"], "readwrite");
const objectStore = transaction.objectStore("toDoList");
const newItem = {
taskTitle: "my task",
hours: 10,
minutes: 10,
day: 10,
month: "January",
year: 2020,
};
const objectStoreRequest = objectStore.add(newItem);
objectStoreRequest.onerror = () => {
console.log(
`æ°è¦ã¢ã¤ãã ã®è¿½å ä¸ã«ã¨ã©ã¼ãçºçãã¾ãã: ${newItem.taskTitle}`,
);
};
};
ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4