我正在创建一个函数来存储数据IndexedDB
,保留一个由我分配一个键的 Map 组成的对象。
使用密钥,我得到对象的值,但它是 aLinkedHashMap
而不是 a Map
,当我尝试访问对象内部的数据时,我总是得到null作为响应。我已经阅读了 API 文档,但我是新手,我不知道如何使它工作。
我打算做的是从 indexedDb 中获取数据并将其分配给一个对象以便能够对其进行操作。
非常感谢提前!!!
/**
* Opens the database, erases it and saves some info
*/
void openDB(var db) {
Map ourList = {'title':'A random title',
'text':'Vivamus sit amet libero turpis, non venenatis urna.',
'data':'2013'};
Map ourList2 = {
'title':'Another random title',
'text':'Vivamus sit amet libero turpis, non venenatis urna.',
'data':'2014'};
db.open()
.then((_) => db.nuke()) /// Erases all the data in the DB
.then((_) => db.save(ourList, '1')) /// Saves an object in the DB
.then((_) => db.save(ourList2, '2'));
print('openDB() was executed'); /// Console control
getTheData(db);
}
/**
* Gets the data from the DB JUST AN EXAMPLE !!
*/
void getTheData(var db){
Map dbData; /// dbData = null for definition
db.open() /// lawndart method
.then((_) => db.getByKey('1')) /// Gets a value depending on the Key
.then((value) => print(value)); /// Prints the value of the key
db.open()
.then((_) => db.getByKey('2'))
.then((value) => print(value)); /// To check != values, use different methods
db.open()
.then((_) => db.getByKey('2'))
.then((value) => print(value.runtimeType)); /// prints the Type of var
/**
* What type of variable it is: _LinkedHashMap
* Classes implement the Map interface and offers mostly the same functionality.
* LinkedHashMap will iterate in the order in which the entries were put into the map
*/
print('getTheData() was executed');/// Console control
}