我有一个 socket.IO 应用程序,它也将数据保存到 MongoDB。
我正在尝试找到一种方法来模糊除最后一个单词之外的整个句子。
行将在哪里的代码:
{#storylines}
<li>{text}</li>
{/storylines}
<input id="newstoryline" name="newstoryline" class="StoryBoard" type="text" placeholder="" onKeyDown="countChars()" onKeyUp="countChars()"/>
套接字.IO:
socket.on('updatechat', function (username, data) {
  $('#newstoryline').before('<li>' + data + '</li>');
});
应用程序还将向模板发送 {maxlines} 将包括剩余的行数。基本上我正在寻找一种说法:
如果 {maxlines} > 0 则模糊除最后一个单词之外的“数据”。
因此,如果来自服务器的消息是“你好,我的名字是 Jim!” 我想成为“* * * ** Jim!”所以用户只能看到单词 Jim!
我正在使用 Node.JS/Mongoose/Socket.IO
我是否必须在客户端实现某种 javascript 函数来检查 {maxlines} > 0 是否然后将模糊效果应用于线条,或者我会在服务器端做些什么?
目前这是服务器发送信息的方式:
app.get('/s/:id', function(req, res){
    Story.findOne({ sid: req.params.id }, function(err, story){
            if (err) {
            res.redirect('/')
        }
        else if(story == null) {
            res.redirect('/')
        }
        else{
    res.render('story', {
        title: 'Storifi',
        storytitle: story.title,
        storylines: story.lines,
        lines: story.maxlines,
        storyid: story.sid
            maxlines: story.maxlines   
                });
            }
        });
});
Socket.IO(服务器端):
socket.on('sendchat', function (data) {
    // we tell the client to execute 'updatechat' with 2 parameters
    io.sockets.in(socket.room).emit('updatechat', socket.username, data);