小编Ale*_*los的帖子

不同的节点js MongoDB不区分大小写

我在Mongo中使用distinct来返回Jquery Autocomplete中的一些值,如下所示:

function Reg(title)
    {
        this.title= title;
    }

exports.find = function(req, res) {
var b=req.params.search;
var query = new Array();
var cadsrch = b.split(' ');
var l = cadsrch.length;
var i = 0;
        for (i = 0; i < l; i++) {
            if(cadsrch[i]!=''){
              query[i]=new RegExp('^'+cadsrch[i], 'i');
            }
        }

var data=new Array();
        db.collection('publication', function(err, collection) {
                collection.distinct('title',{content:{'$all':query}},{'$or':[{type:'an'},{type:'pub'}]},
                  function(err, items) {
                         var l=items.length,i=0;
                         for (i=0;i<l;i++){
                            data[i]=new Reg(items[i]);
                         }
                         res.jsonp(data);
                         }
                )
        });
};
Run Code Online (Sandbox Code Playgroud)

问题是列的标题是在区分大小写的情况下工作,我的意思是例如汽车与汽车不同,我不知道是否有办法避免这种情况并将汽车与汽车相同

case distinct node.js

6
推荐指数
2
解决办法
2587
查看次数

每页表格标题 Word PHPWord

我正在使用 PHPWord 生成报告,但我找不到在每个页面中保留表标题的方法。问题是我可以\xc2\xb4t 为单元格提供样式,并且标题和主表之间有一些空间。

\n\n

我尝试这样做,但我认为这不是最好的解决方案:

\n\n
<?php\nrequire_once \'PHPWord.php\';\n\n// New Word Document\n$PHPWord = new PHPWord();\n\n// New portrait section\n$section = $PHPWord->createSection();\n\n// Define table style arrays\n$styleTable = array(\'borderSize\'=>6, \'borderColor\'=>\'006699\', \'cellMargin\'=>80);\n$styleFirstRow = array(\'borderBottomSize\'=>18, \'borderBottomColor\'=>\'0000FF\', \'bgColor\'=>\'66BBFF\');\n\n// Define cell style arrays\n$styleCell = array(\'valign\'=>\'center\');\n$styleCellBTLR = array(\'valign\'=>\'center\', \'textDirection\'=>PHPWord_Style_Cell::TEXT_DIR_BTLR);\n\n// Define font style for first row\n$fontStyle = array(\'bold\'=>true, \'align\'=>\'center\');\n\n// Add table style\n$PHPWord->addTableStyle(\'myOwnTableStyle\', $styleTable, $styleFirstRow);\n$header = $section->createHeader();\n$table = $header->addTable();\n$table->addRow(900);\n$table->addCell(2000,$styleCell)->addText(\'Row1\',$fontStyle);\n$table->addCell(2000,$styleCell)->addText(\'Row2\',$fontStyle);\n$table->addCell(2000,$styleCell)->addText(\'Row3\',$fontStyle);\n$table->addCell(2000,$styleCell)->addText(\'Row4\',$fontStyle);\n$table->addCell(500,$styleCell)->addText(\'Row5\',$fontStyle);\n// Add table\n$table = $section->addTable(\'myOwnTableStyle\');\n\n// Add more rows / cells\nfor($i = 1; $i <= 1000; $i++) {\n    $table->addRow();\n    $table->addCell(2000)->addText("Cell $i");\n    $table->addCell(2000)->addText("Cell $i");\n …
Run Code Online (Sandbox Code Playgroud)

php each phpword

5
推荐指数
1
解决办法
4365
查看次数

从Node.js中查询MongoDB中的like

如何使用Node.js在MongoDB中进行类似的查询?

这是我的源代码,但它不起作用:

exports.findAll = function(req, res) {
    var country=req.params.country; 
    db.collection('wines', function(err, collection) {
        collection.find({ 'country': new RegExp('/'+country+'/i') }).toArray(function(err, items) {
            res.jsonp(items);
        });
    });
};
Run Code Online (Sandbox Code Playgroud)

mongodb node.js

4
推荐指数
1
解决办法
7420
查看次数

如何在节点js中使用jquery自动完成

我试图用节点休息服务实现jquery自动完成,但我可以让它工作.

这是我的源代码:

自动完成:

$('#search').autocomplete({
        source: function (req, res) {
            $.ajax({
                url: "http://www.example.com:3000/autocomplete",
                dataType: "jsonp",
                type: "GET",
                data: {
                    term: req.term 
                },
                success: function (data) {
                    res($.map(data.results, function (item) {
                        return {
                            label: item.id,
                            value: item.id
                        };
                    }));
                },
                error: function (xhr) {
                    alert(xhr.status + ' : ' + xhr.statusText);
                }
            });
        }    
    });
Run Code Online (Sandbox Code Playgroud)

节点服务

exports.find = function(req, res) {
var b=req.params.term;
console.log(b);
db.collection('publication', function(err, collection) {
      collection.find({type:'pub',content: new RegExp(b, 'i') }).limit(5).toArray(function(err, items) {
                res.jsonp(items);
            });
        });
};
Run Code Online (Sandbox Code Playgroud)

b在控制台中显示为未定义,并且自动完成功能不起作用

rest service jquery autocomplete

4
推荐指数
1
解决办法
1万
查看次数

与mongo和节点js不同

我试图使用节点js实现的休息服务来获取记录,以填充jquery的自动完成.这是方法

db.collection('publication', function(err, collection) {
        collection.distinct('title',{'$or':[{type:'an'},{type:'pub'}]}).toArray(function(err, items) {
                res.jsonp(items);
            });
        });
};
Run Code Online (Sandbox Code Playgroud)

mongo中的查询工作 - >

 db.publication.distinct('title',{'$or':[{type:'an'},{type:'pub'}]}) 
Run Code Online (Sandbox Code Playgroud)

返回["Product","Event"]但是当我使用find时结果是不同的,find会是 - >

{ "_id" : ObjectId("51fbb2124e49d03810000000"), "title" : "Anuncio" }
{ "_id" : ObjectId("51fbb2ae4e49d03810000001"), "title" : "Evento" }
Run Code Online (Sandbox Code Playgroud)

使用第二种方式自动完成工作,但第一种方式不行

节点中显示的错误是:object不是函数.

最后我需要的是返回一个带有记录的json来填充自动填充,填充如下:

$('#search').autocomplete({
        source: function(req, res) {
            $.ajax({
                url: "http://www.example.com:3000/autocomplete/" + req.term ,
                dataType: "jsonp",
                type: "GET",
                data: {
                    term: req.term
                },
                success: function(data) {
                    res($.map(data, function(item) {
                        return {
                            label: item.title,
                            value: item.title
                        };
                    }));
                },
                error: function(xhr) {
                    alert(xhr.status + ' : …
Run Code Online (Sandbox Code Playgroud)

rest jquery distinct mongodb node.js

1
推荐指数
1
解决办法
6859
查看次数

标签 统计

node.js ×3

distinct ×2

jquery ×2

mongodb ×2

rest ×2

autocomplete ×1

case ×1

each ×1

php ×1

phpword ×1

service ×1