小编ket*_*sek的帖子

Javascript删除对象属性不起作用

我正在MEAN.js上运行一些项目,我遇到了以下问题.我想做一些用户的配置文件计算并将其保存到数据库.但是用户模型中的方法存在问题:

UserSchema.pre('save', function(next) {
    if (this.password && this.password.length > 6) {
        this.salt = new Buffer(crypto.randomBytes(16).toString('base64'), 'base64');
        this.password = this.hashPassword(this.password);
    }
    next();
});
Run Code Online (Sandbox Code Playgroud)

如果我将使用我的更改发送密码,它将更改凭据,因此用户下次无法登录.我想在保存之前从用户对象中删除密码,但是我无法做到(让我们看看下面代码中的注释):

exports.signin = function(req, res, next) {
    passport.authenticate('local', function(err, user, info) {
        if (err || !user) {
            res.status(400).send(info);
        } else {
            /* Some calculations and user's object changes */
            req.login(user, function(err) {
                if(err) {
                    res.status(400).send(err);
                } else {
                    console.log(delete user.password); // returns true
                    console.log(user.password); // still returns password :(
                    //user.save();
                    //res.json(user);
                }
            });
        }
    })(req, res, next);
}; …
Run Code Online (Sandbox Code Playgroud)

javascript mean-stack

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

启用画布移动滚动

我有一个手机游戏,当用户结束游戏时,我希望他能够向下滚动以获得网站的其他信息。现在他做不到,因为画布正在收集所有触摸和其他输入信息:-(游戏在Pixi.js中

javascript jquery canvas

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

SVG stroke-linecap对Firefox中的圆圈不起作用?

我有svg stroke-linecap属性的问题.我在AngularJS中有圆形进度条,我想将外圆(蓝色圆圈)设置为圆形"端".看看这个小提琴.

<svg ... height="130" width="130">
<!-- ngIf: background -->
<circle ... 
    ng-if="background" 
    fill="#fff" 
    class="ng-scope" 
    stroke-width="13" 
    stroke="#cc3399" 
    r="57.5" 
    cy="65" 
    cx="65" 
    stroke-linecap="round" 
/>
<!-- end ngIf: background -->
<circle ... 
    fill="none" 
    stroke-dashoffset="36.12831551628261" 
    stroke-dasharray="361.28315516282623" 
    stroke-width="13" 
    stroke="#432db3" 
    stroke-linecap="round" 
    r="57.5" 
    cy="65" 
    cx="65" 
    transform="rotate(-89.9, 65, 65)"
/>
</svg>
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

firefox svg

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

C++ DevIL函数ilLoadImage - 程序退出,访问冲突

我有一个以这种方式定义的文件路径:

const char* GROUND_TEXTURE_FILE = "objects/textures/grass.jpg";
Run Code Online (Sandbox Code Playgroud)

这是我用来加载图像的函数:

bool loadTexImage2D(const string &fileName, GLenum target) {
    ...
    // this will load image data to the currently bound image
    // at first, we must convert fileName, for ascii, this method is fine?
    wstring file(fileName.begin(), fileName.end());

    if(ilLoadImage(file.c_str()) == IL_FALSE) { //here the program falls
Run Code Online (Sandbox Code Playgroud)

我的代码有什么问题?ilLoadImage调用时为什么程序会掉线?我认为,file.c_str()作为一种wchar_t *类型应该可以正常工作吗?谢谢你的回答:)

c++ devil

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

在 Service Worker 更新时重新加载 Create-react-app

我想修改create-react-appservice worker文件并实现弹出消息,如果新的 service worker 准备好激活,它将要求用户更新应用程序。我几乎完成了解决方案,但有一个陷阱。我想在用户确认 service worker 更新弹出窗口时重新加载应用程序,所以我在register函数的末尾添加了一些代码,见下文:

export default function register(config) {
  if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
    // The URL constructor is available in all browsers that support SW.
    const publicUrl = new URL(process.env.PUBLIC_URL, window.location)
    if (publicUrl.origin !== window.location.origin) {
      // Our service worker won't work if PUBLIC_URL is on a different origin
      // from what our page is served on. This might happen if a CDN is used …
Run Code Online (Sandbox Code Playgroud)

reactjs service-worker create-react-app

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

UML - 箭头上的十字架是什么意思?

我正在研究一些UML材料,我遇到了一个奇怪的事情:在箭头/关联的一边交叉.这是什么意思?它经常用于我正在研究的材料中.请看下面的图片

交叉UML线

uml

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

从Twitter API日期创建javascript日期对象–跨浏览器解决方案

我的Twitter API created_at date有一个大问题,它具有以下格式:Tue Apr 18 07:24:05 +0000 2017...我想从中创建javascript Date对象,但无法找到跨浏览器的解决方案。到目前为止,我已经尝试过:

  • new Date(Date.parse(input.replace(/( \+)/, ' UTC$1'))); –在Safari中返回null
  • new Date((input || "").replace(/-/g,"/").replace(/[TZ]/g," ")); –在IE11中返回null
  • moment.js库引发有关不赞成使用的方法的警告,并退回javascript Date()

有人可以帮我弄清楚吗?非常感谢你!

javascript twitter date

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

在List中查找String的索引 - Haskell

我有以下输入:

["56", "+", "49", "-", "2", "+", "15]
Run Code Online (Sandbox Code Playgroud)

所以它是一个字符串列表,我想得到"+" - [1,5]的索引.我怎样才能实现它?

haskell

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