首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >indexed_db openCursor最新更改

indexed_db openCursor最新更改
EN

Stack Overflow用户
提问于 2013-02-27 16:13:32
回答 1查看 69关注 0票数 0

下面的代码被发布为openCursor的新处理。谁能告诉我下面的代码现在是否可以工作(Dart r18915),以及"values“变量是什么?

代码语言:javascript
复制
store.openCursor(autoAdvance: true).listen(
    (cursor) => values.add(onCursor(cursor)),
    onDone: () => completer.complete(values),
    onError: (e) => completer.completeError(e));
return completer.future;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-27 22:24:38

我不确定您的onCursor()函数在做什么/调用什么。我假设你的值变量是一个列表。

我自己也做了类似的事情,但使用的是回调,而不是将来/完成器。这里只有一个很小的函数片段。我将把它写出来,希望能添加一些细节:

代码语言:javascript
复制
// Accept the indexeddb Database, and return a future which
// will provide the list of values from 'someKey'
Future<List<String>> getSomeKeyValues(Database db) {
  var values = new List<String>();
  var completer = new Completer();

  var store = db.transaction('DB_STORE', 'readwrite').objectStore('DB_STORE');
  store.openCursor(autoAdvance: true).listen((cursor) {
      if(cursor != null && cursor.value != null) {
        // Note cursor.value is actually a Map<String, String> 
        // of collection's key and value
        values.add(cursor.value['someKey']); // get the value key 'someKey'
      }
    }, onDone: () => completer.complete(values),
    onError: (e) => completer.completeError(e));

  return completer.future;
}

然后我们会像这样调用这个函数:

代码语言:javascript
复制
getSomeKeyValues(myDatabase).then((results) {
  for(var value in results) {
    print(value);
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15107081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档