2
如何提取SUM取決於ID或東西,目標是獲得所有值的SUM?
我能夠獲得所有的值,但是SUM SUM可以存放其單個變量,因此必須有某種分段來對它們進行SUM?有任何想法嗎?如何獲得所有CouchDB值的SUM?
$db = $.couch.db("fuel");
function refreshFuel() {
$("div#fuel").empty();
$db.view("fuel/bill", {success: function(data) {
for (i in data.rows) {
id = data.rows[i].id;
bill = data.rows[i].key;
date = data.rows[i].value;
html = '<div class="fuel">' +
'<span class="bill">' + bill + '</span> ' +
'<span class="date">' + date + '</span> ' +
'</div>';
$("div#fuel").append(html);
}
}});
}
function getAll(){
$("div#all").empty();
$db.view("fuel/bill", {success: function(data) {
for (i in data.rows) {
id = data.rows[i].id;
bill = data.rows[i].key; // how to get SUM of all this values
date = data.rows[i].value;
html =
'<span class="all">' + bill + '</span> '
$("div#all").append(html);
}
}});
}
編輯:
我的JSON是這樣的:
{
"_id": "1a06982d3434f37a04a02dbf360010ee",
"_rev": "1-c8c9d5252a76abd8f565ff82bf63b0e8",
"value": "200",
"date": "2011-09-05T10:28:55.101Z"
}
和我的看法是這樣的:
function(doc) {
if (doc.value, doc.date) {
emit(doc.value,doc.date, doc);
}
}
也如果我添加reduce.js我失去了正常值,它只顯示_sum版本?如何提取這兩個值? –
只需使用?reduce = false查詢:)有關更多信息,請參閱http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options。 –
明白了,非常感謝,歡呼! –