1
我們如何從表格的所有記錄中獲得最後的40條記錄。使用索引分貝的dexie js獲取計數記錄。
據我所知,我們可以得到在索引分區表中退出的記錄數量。
出於同樣的...
function doCount(){
db.friends.toCollection().count(function (count) {
console.log(count + " friends in total");
});
上面會返回任何計數是table.Now我想從table.Every時間表的最後40條記錄都會有不同的記錄。 是否可以這樣做。 我們是否也可以使用各個與計數!!我想要得到計數,以及任何關鍵數據,我需要返回這些數據並顯示它。
var db = new Dexie("MyDB");
db.version(1).stores({
friends: "id,name,shoeSize"
});
db.open();
//
// Populate some data
//
function populateSomeData() {
log("Populating some data", "heading");
return db.transaction("rw", db.friends, function() {
db.friends.clear();
db.friends.add({ id:1,name: "David", shoeSize: 43 });
db.friends.add({ id:2,name: "Ylva", shoeSize: 37 });
db.friends.add({ id:3,name: "Jon", shoeSize: 44 });
db.friends.add({id:4, name: "Måns", shoeSize: 42 });
db.friends.add({ id:5,name: "Daniel", shoeSize: 39 });
db.friends.add({ id:6,name: "Nils", shoeSize: 45 });
db.friends.add({ id:7,name: "Zlatan", shoeSize: 47 });
// Log data from DB:
db.friends.orderBy('name').each(function (friend) {
log(JSON.stringify(friend));
});
}).catch(function (e) {
log(e, "error");
});
}
//
// Examples
//
function equalsAnyOf() {
log("db.friends.where('name').anyOf('David', 'Zlatan', 'Daniel')", "heading");
return db.friends.where('name').anyOf('David', 'Zlatan', 'Daniel')
.each(function (friend) {
log(JSON.stringify(friend));
});
}
function equalsIgnoreCase() {
log("db.friends.where('name').equalsIgnoreCase('david')", "heading");
return db.friends.where('name').equalsIgnoreCase('david')
.each(function (friend) {
log(JSON.stringify(friend));
});
}
function startsWithIgnoreCase() {
log("db.friends.where('name').startsWithIgnoreCase('da')", "heading");
return db.friends.where('name').startsWithIgnoreCase('da')
.each(function (friend) {
log(JSON.stringify(friend));
});
}
function logicalOR() {
log("db.friends.where('name').startsWithIgnoreCase('da').or('shoeSize').below(40)", "heading");
return db.friends.where('name').startsWithIgnoreCase('da')
.or('shoeSize').below(40)
.each(function (friend) {
log(JSON.stringify(friend));
});
}
function logicalAND() {
log("db.friends.where('name').startsWithIgnoreCase('da').and(function (friend) { return friend.shoeSize > 40; })", "heading");
return db.friends.where('name').startsWithIgnoreCase('da')
.and(function (friend) { return friend.shoeSize > 40; })
.each(function (friend) {
log(JSON.stringify(friend));
});
}
\t \t var lakho =[];
\t \t function doCount(){
\t \t \t db.friends.toCollection().count(function (count) {
\t \t \t lakho = count;
\t \t \t console.log(count + " friends in total");
\t \t \t var div = document.getElementById('po');
\t \t \t div.innerHTML = div.innerHTML + count;
\t \t });
\t \t console.log(lakho + "lakho");
\t \t
\t \t db.friends.where('id').between(1,3).count(function (count) {
\t \t \t console.log(count + " friends in total");
\t \t \t var div = document.getElementById('po');
\t \t \t div.innerHTML = div.innerHTML + count;
\t \t });
\t \t
\t \t db.friends
\t \t .where('shoeSize').above(9)
\t \t .each (function (friend) {
\t \t \t console.log("Found big friend: " + friend.name);
\t \t });
}
//
// Helpers
//
function log(txt, clazz) {
var li = document.createElement('li');
li.textContent = txt.toString();
if (clazz) li.className = clazz;
document.getElementById('log').appendChild(li);
}
function runSamples() {
populateSomeData()
.then(equalsAnyOf)
.then(equalsIgnoreCase)
.then(startsWithIgnoreCase)
.then(logicalOR)
.then(logicalAND)
\t \t \t \t .then(doCount)
.catch(function (e) {
log(e, "error");
});
}
<script src="https://unpkg.com/[email protected]/dist/dexie.js"></script>
<body onload="runSamples();">
<ul id="log"></ul>
\t <div id="po"> </div>
</body>
嗨大衛, 你的忠實粉絲。 db.friends .orderBy( 'ID') .reverse() .limit(3) 。每個(函數(朋友){ 的console.log( 「從最後一個記錄」 + JSON.stringify(朋友)) ; }); 這將只返回一個記錄donno爲什麼我認爲它應該返回我所有最後3條記錄,但只有最後一條記錄。 –