Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 从CouchDB列表输出html_List_Couchdb - Fatal编程技术网

List 从CouchDB列表输出html

List 从CouchDB列表输出html,list,couchdb,List,Couchdb,我试图在CouchDB 0.11中创建一个列表,该列表用一些html进行响应,我在让CouchDB设置正确的头时遇到问题,无论我怎么做,我都只得到一个应用程序/json响应头。这是我的列表函数 function(head, req) { var rows = []; var row; while(row = getRow()) { rows.push(row); } rows.sort(function(a, b) {

我试图在CouchDB 0.11中创建一个列表,该列表用一些html进行响应,我在让CouchDB设置正确的头时遇到问题,无论我怎么做,我都只得到一个应用程序/json响应头。这是我的列表函数

function(head, req) {

    var rows = [];
    var row;

    while(row = getRow()) {
        rows.push(row);
    }

    rows.sort(function(a, b) {
        return (Date.parse(a['value']['last_logtime']) - Date.parse(b['value']['last_logtime']));
    });

    provides("html", function() {
        var content = "<html><head><title>foobar</title></head><body>";
        for(var i in rows) {
            content = content + rows[i]['value']['last_logtime']+"<br/>";
        }
        content = content + "</body></html>";
        return content;
    });

}
功能(头部,需求){
var行=[];
var行;
while(row=getRow()){
行。推(行);
}
行排序(函数(a,b){
return(Date.parse(a['value']['last_logtime'])-Date.parse(b['value']['last_logtime']);
});
提供(“html”,函数(){
var content=“foobar”;
用于(行中的变量i){
content=content+rows[i]['value']['last_logtime']+“
”; } 内容=内容+“”; 返回内容; }); }

有什么建议我做错了什么吗?

事实上,我自己也明白了


getRow()的东西需要放在函数中:)

谢谢,你提到的很好,我一直在努力解决这个问题,但没有意识到。共享一个捕获数据的通用方法,这样就可以在每个提供中调用它,这也很有用,因为您不需要重复相同的任务;)谢谢你,伙计