小编chr*_*dam的帖子

如何检测html FileReader的编码?

txt文件可能是utf8/GB2312,....但如果上传到我的服务器,我只有ascii.如何检测文件编码,所以我可以在readAsText()中设置?

$("#fileinput").change(function(evt){
  if (!checkSupport())return; 
  var f = evt.target.files[0]; 
  if (!f) return;
  var r = new FileReader();
  r.onload = function(evt){   //file loaded successfuly
    g_fname=f.name;
    g_contents = evt.target.result;
    curpage.val(0);
    read_article();
  }
  r.readAsText(f,'GB2312');
});
Run Code Online (Sandbox Code Playgroud)

jquery encoding filereader

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

如何删除粘贴上的p标签以外的其他html标签?

我的内联文本编辑器遇到了一些麻烦。很简单,用户有权在textarea div上复制粘贴。没问题。但我不想让他们将HTML贴上图片和div元素。

我用过

valid_elements: "p,br,b,i,strong,em",
Run Code Online (Sandbox Code Playgroud)

它删除p tags内容的样式。

为此,但这不是根据我的要求的解决方案。

我也尝试过,paste_postprocess但是最新版本的tinymce却没做任何事情。

而且我还尝试了许多已经发布在此社区中的解决方案。但是它们都不适合我,因为我使用的是最新版本tinymce 4.0.26

我知道我可以通过禁用右键单击来防止复制粘贴。但这不是一个好主意。

有没有什么办法来过滤仅p tagstyle从HTML内容?

因此,如果有人on copy paste使用的最新版本tinymce

请帮忙。

html javascript jquery copy-paste tinymce-4

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

如何使单词中的每个字母在悬停时发生变化

假设我的网站上某个段落中有一个单词“IamGreat”,我希望它在悬停时更改为“Good4you”。但是,我不想更改整个单词,而是希望每个字母单独更改。因此,如果我将鼠标悬停在字母“I”上,它将变成字母“G”,字母“r”将变成数字“4”等。这两个单词的长度相同。如果可能的话,我还想更改正在更改的字母的CSS(字体颜色、字体变体等)。有没有办法使用 jQuery 或 javascript 来做到这一点?

html javascript css jquery

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

在 Spring 中查找的聚合查询

我正在使用 Spring 框架在我的 mongodb 上执行聚合。但是,查找一直失败,我不明白为什么。这是查询:

Aggregation aggregation = newAggregation(
    match(Criteria.where("idOfUser").is(loggedInAccount.getId())),
    group("imgID"),
    new CustomAggregationOperation(
        new BasicDBObject("$lookup",
        new BasicDBObject("from","img")
            .append("localField","_id")
            .append("foreignField","_id")
            .append("as","uniqueImgs")
        )
    ),
    limit(pageable.getPageSize()),
    skip(pageable.getPageSize()*pageable.getPageNumber())
);

AggregationResults aggregationResults = mongo.aggregate(aggregation, "comment", String.class); //Using String at the moment just to see the output clearly.
Run Code Online (Sandbox Code Playgroud)

CustomAggregationOperation 如下:

public class CustomAggregationOperation implements AggregationOperation {
    private DBObject operation;

    public CustomAggregationOperation (DBObject operation) {
        this.operation = operation;
    }

    @Override
    public DBObject toDBObject(AggregationOperationContext context) {
        return context.getMappedObject(operation);
    }
}
Run Code Online (Sandbox Code Playgroud)

无法识别 Spring MongoDB 版本的查找,这就是我使用它的原因CustomAggregationOperation。AFAIK它不应该影响它。

理想情况下,我想要发生的是:

  1. 获取用户的所有评论。 …

java spring mongodb aggregation-framework spring-data-mongodb

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

从子文档数组获取部分模型数组(MongoDB C#驱动程序)

我正在尝试接收仅使用MongoDB C#驱动程序填充的子字段的新数组。例如,我有以下文档:

{
    "_id" : "fca739d0-cddd-4762-b680-597d2996404b",
    "Status" : 1,
    "AccountId" : "1112",
    "Timestamp" : ISODate("2016-04-27T13:46:01.888Z"),
    "CartItems" : [ 
        {
            "ProductId" : "222",
            "Price" : 100,
            "ShippingPrice" : 20,
            "Quantity" : 3
        }, 
        {
            "ProductId" : "504",
            "Price" : 200,
            "ShippingPrice" : 20,
            "Quantity" : 2
        }, 
        {
            "ProductId" : "504",
            "Price" : 200,
            "ShippingPrice" : 20,
            "Quantity" : 1
        }, 
        {
            "ProductId" : "504",
            "Price" : 200,
            "ShippingPrice" : 20,
            "Quantity" : 1
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试CartItems仅接收具有的新数组的文档,ProductId …

c# mongodb mongodb-.net-driver

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

如何在mongoose中填充嵌套实体?

我有以下mongoose架构结构

userSchema = new Schema({
    roles: [
        role: {type: Schema.Types.ObjectId, ref: 'Role' }
    ]
})

rolesSchema = new Schema({
  name: String,
  roleEntities: [
    {
      entity : {type: Schema.Types.ObjectId, ref: 'RoleEntity' },
      abilities : [{type: Schema.Types.ObjectId, ref: 'Ability' }]
    }
  ]
}

roleEntitiesSchema = new Schema({
  name: String
})

abilitiesSchema = new Schema({
  name: String
})
Run Code Online (Sandbox Code Playgroud)

如何在USER模型上执行查找时填充所有这些嵌套文档?

我尝试使用populate如下

User.find(ctx.request.query).populate(
      {path: 'roles.role'
      ,populate: { path: 'roleEntities.entity'}
    }).
    exec()
Run Code Online (Sandbox Code Playgroud)

但它并没有解决roleEntities.entity

mongoose mongodb node.js mongoose-populate

5
推荐指数
4
解决办法
5475
查看次数

Spring Data - MongoDb聚合$ ifNull

db.collection.aggregate([
    {$match : { name : "name" } },
    {$project: {
        name: 1,
        sent: { 
            $size: {
                "$ifNull": [ "$audience", [] ]
            } 
        }
    }
}]);
Run Code Online (Sandbox Code Playgroud)

如何使用Spring数据进行上述mongo聚合?

java spring mongodb spring-data

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

PHP CLI pcntl无法在PHP7.0 Ubuntu xenial服务器上运行

我在PHP 5.5.9中使用此脚本:

declare(ticks = 1);

pcntl_signal(SIGTERM, array($this, 'stopSending'));
pcntl_signal(SIGINT, array($this, 'stopSending'));
pcntl_signal(SIGUSR1, array($this, 'stopSending'));
pcntl_signal(SIGUSR2, array($this, 'stopSending'));
pcntl_signal(SIGQUIT, array($this, 'stopSending'));
pcntl_signal(SIGHUP, array($this, 'stopSending'));

public function stopSending($signals)
{       
    echo "hello";
    exit();
}

while (true) {
    // some logic
}
Run Code Online (Sandbox Code Playgroud)

在Ubuntu 14中工作正常,但是当尝试使用PHP7.0在Ubuntu 16.04中执行并尝试发送信号(kill PID)时,PHP CLI不会停止并保持runnig.

在Ubuntu 16.04中,我检查了pcntl扩展,这没关系:

>php -m | grep pcntl
pcntl
Run Code Online (Sandbox Code Playgroud)

我跑步时没有任何错误,但都没有停止(或显示回声).

PHP7和pcntl有问题吗?

UPDATE

问题是将while循环封装到函数中时:

function start()
{
    while (true) {
        // some logic
    }
}

declare(ticks = 1);

pcntl_signal(SIGTERM, "stopSending");
pcntl_signal(SIGINT, "stopSending");
pcntl_signal(SIGUSR1, "stopSending");
pcntl_signal(SIGUSR2, "stopSending");
pcntl_signal(SIGQUIT, "stopSending");
pcntl_signal(SIGHUP, …
Run Code Online (Sandbox Code Playgroud)

php ubuntu php-7 ubuntu-16.04

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

MongoDB节点驱动程序当前聚合的计数

我正在使用mongodb作为节点,我正在尝试根据一些设置过滤器聚合一组文档,然后将其限制为10.我将它聚合得很好并且限制很好但是我需要在之前获得聚合文档的总数我把它们限制在10.

这是我的代码.

var qry = [];
if (filter.FocusArea && filter.FocusArea != "(None)") {
    qry.push({
        $match: { 'ProgramAreaId': filter.FocusArea }
    });
}
if (filter.Status && filter.Status != "(None)") {
    qry.push({
        $match: { 'StatusId': filter.Status }
    });
}
if (filter.ProgOfficer && filter.ProgOfficer != "(None)") {
    qry.push({
        $match: { 'ProgramOfficerId': filter.ProgOfficer }
    });
}
if (filter.Fund && filter.Fund != "(None)") {
    qry.push({
        $match: { 'FundId': filter.Fund }
    });
}
 var skipNbr = (parseInt(filter.Page) * 10 - 10);
qry.push({ $project: { _id: '$_id', count: …
Run Code Online (Sandbox Code Playgroud)

javascript mongodb node.js aggregation-framework mongodb-aggregation

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

字段必须是 BSON 类型的对象

我正在创建一个动态过滤器对象,用于从 nodejs 中的 mongodb 查询数据。但是 mongo 抛出错误“无法解析过滤器对象,过滤器必须是 BSON 类型的对象”。这是我的参考函数代码和日志屏幕截图

function GetDeviceByFilter(args, cb) {
  var query = args.qs;
  var andQry = [];
  var orQry = [];
  var type = parseInt(query.type);
  try {
    if(type === uType.s){
      andQry.push({sel: parseInt(query.idx)});
      if(query.isSold === "0"){
        orQry.push({uid: {$exists: false}})
        orQry.push({uid: 0});
        orQry.push({uid: null});
      } else if(query.isSold === "1"){
        orQry.push({uid : {$gt: 0}});
      }
    } else if(type === uType.a){
      andQry.push({admn: parseInt(query.idx)});
      if(query.isSold === "0"){
        orQry.push({sel: {$exists: false}})
        orQry.push({sel: 0});
        orQry.push({sel: null});
      } else if(query.isSold === "1"){ …
Run Code Online (Sandbox Code Playgroud)

arrays json mongodb node.js mongodb-query

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