0

Chrome 25 と最新バージョンのIDBWrapper を使用しています。

ストアを作成します:

var countryStore = new IDBStore({
    dbVersion: version,
    storeName: countryTable,
    keyPath: 'id',
    autoIncrement: true,
    onStoreReady: function () {
        console.log('Country store ready, go ahead!');
        americanGivingDB.countryStore.count(function (result) {
            console.log("The amount found in the countryStore was " + result);
            if(result == 0){
                initializeCountryStore(countryStore, countryDeferred);
            } else {
                countryDeferred.resolve();
            }
        });
    },
    indexes: [ {name : "areas", keypath: "area", unique: false, multiEntry:true}, {name: "years", keypath: "year", unique: false, multiEntry: true}]
});

次に、大量のバッチを追加します。

for(var i = 0; i < lines.length; i++) {
   var fields = lines[i].split(", "); // Comma-separated values

   valueToAdd = {
       id: id,
       area: fields[0],
       program: fields[1],
       year: fields[2],
       amount: fields[3]                    
    }
    id++;

    operations.push( {type: "put", value: valueToAdd});
}

countryCSVxhr.onload = function(e) {  
    console.log("onload found number of operations to add are " + operations.length);
    status("country dataset downloaded, adding to local storage.");
    db.batch(operations, function (result) {
        status("finished loading the country table");
        console.log("finished loading the country table");
        americanGivingDB.countryStore.count(function (result) {
            status("country dataset added to local storage");
            console.log("The amount found in the countryStore was " + result);
            countryDeferred.resolve();
        });
    }, function (error) {
        console.log("error", error);
    });
}

次に、インデックスに対してクエリを実行します。

americanGivingDB.countryStore.query( function(results){
    //console.log("finished querying the store " + results);
    var returnString = "";
    for(var i = 0; i < results.length; i++){
        returnString = returnString + results[i].area + " \n";
    }
    console.log("the area names are: \n" + returnString);
    }, 
    {
        index: "areas",
        keyRange: americanGivingDB.countryStore.makeKeyRange({
            upper: "Z"
            }),
        filterDuplicates: true,
        onError: americanGivingDB.onErrorHandler
    }
);

空の結果セットを返します。クロム内のリソースを確認すると、インデックスが空白になっています。空白にする必要があるかどうかはわかりません。

何が間違っている可能性がありますか?

4

2 に答える 2

1

私の問題はタイプミスでした。データストアにコンストラクターを使用する場合、大文字の使用には十分注意する必要があります。「キーパス」は「キーパス」である必要があります。

var countryStore = new IDBStore({
dbVersion: version,
storeName: countryTable,
keyPath: 'id',
autoIncrement: true,
onStoreReady: function () {
    console.log('Country store ready, go ahead!');
    americanGivingDB.countryStore.count(function (result) {
        console.log("The amount found in the countryStore was " + result);
        if(result == 0){
            initializeCountryStore(countryStore, countryDeferred);
        } else {
            countryDeferred.resolve();
        }
    });
},
indexes: [ {name : "areas", keyPath: "area", unique: false, multiEntry:true}, {name: "years", keyPath: "year", unique: false, multiEntry: true}]
});
于 2013-03-21T22:43:48.887 に答える
0

何がうまくいかないのかわかりませんが、私のライブラリhttps://bitbucket.org/ytkyaw/ydn-db/wiki/Homeを試すことができます 。

var schema = {
  stores: [{
     storeName: countryTable,
     keyPath: 'id',
     autoIncrement: true,
    indexes: [ {name : "areas", keypath: "area", unique: false, multiEntry:true}]
  }]
}
var countryStore = new ydn.db.Storage('db name', schema);
countryCSVxhr.onload = function(e) { 
  // process countryData as array
  countryStore.put(countryTable, countryData);
  countryStore.count(countryTable).done(function (numberOfRecord) {
     console.log(numberOfRecord);
  });
  countryStore.values(countryTable, 'areas', IDBKeyRange.upperBound('Z')).done(function (records) {
     console.log(records);
   });
};
于 2013-03-20T00:33:15.903 に答える