2011-03-03 66 views
2

如何仅使用地图查询视图的地图,如何使用evently查询减少?couchdb查询地图视图,而不是减少视图

这里是我迄今为止在data.js:

function(data) { 
    var numRows = data.rows.map(function(r) { 
    return r 
    }); //this is returning an object that is the result of the reduce function 
     // but I want the total_rows of the map function 

    var sum = data.rows.reduce(function(r) { 
    return r.value 
    }); //this returns the sum of all row values 
    var avg = sum.value/numRows 
    $.log(avg); 
    $.log(numRows); 
    return {'total': numRows, 'average': avg} 
}; 

我想这是从查询和值的平均值返回的行总数。

在此先感谢您的帮助。

回答

2

我目前没有couchapp手头现在测试,但我认为你很困惑JavaScript map function与CouchDB查看地图功能。做data.rows.map()您正在拨打data.rows阵列上的Array.map功能。你在找什么应该在data.total_rows

阅读this tutorial了解更多信息。

UPDATE:行数是data.rows.length。