小编Tak*_*aki的帖子

Mongoose - 无法在路径notification.from上填充排序,因为它是文档数组的子属性

我有一个非常简单的mongo方案,我正在用猫鼬访问

我可以使用populate将用户名和名字映射到每个通知的字段,问题是我似乎无法在日期字段上进行任何排序

使用此代码我得到一个错误

MongooseError:无法在路径notification.from上填充sort,因为它是文档数组的子属性

是否有可能以不同的方式或更新的方式(深度填充,虚拟)这样做?我在使用Mongoose 5.

我宁愿不使用vanilla javascript来对对象进行排序或创建单独的模式

var UserSchema = new Schema({  
    username: String,
    firstname: String,
    notifications: [
        {  
            from: { type: Schema.Types.ObjectId, ref: 'User'},
            date: Date,
            desc: String
        }
    ]
});

app.get('/notifications', function(req, res) {
    User.findOne({ _id: req._id }, 'notifications')
    .populate({
        path: 'notifications.from',   
        populate: {
            path: 'from',
            model: 'User',
            options: { sort: { 'notifications.date': -1 } }            
        }
    }) 
    .exec(function(err, user) {
        if (err) console.log(err)
    })
});
Run Code Online (Sandbox Code Playgroud)

关于Mongo,这个可能重复的事实差不多已经有两年了.我问是否有更新或不同的方式在Mongoose中这样做,因为自2016年以来它已经改变了一些新的功能.

javascript mongoose mongoose-populate mongoose-schema

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

Bootstrap 导航栏通知徽章

我正在建立一个允许用户相互发送消息的网站。我使用 AJAX 获得了许多新消息。因此,我只需要找到一种如何在用户导航栏中显示徽章的方法。

这是我想要实现的目标:

在此处输入图片说明

我想徽章使用创建<span class="badge badge-pill badge-primary">1</span>

我的导航栏代码:

<nav class="navbar navbar-expand-md navbar-dark bg-dark navbar-laravel" style="margin-bottom: 20px;">
    <div class="container">
        <a class="navbar-brand" href="#">Website</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <!-- Left Side Of Navbar -->
            <ul class="navbar-nav mr-auto">
                <li class="nav-item">
                    <a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="messages">Messages <span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">People <span class="sr-only">(current)</span></a>
                </li>
                <li …
Run Code Online (Sandbox Code Playgroud)

html css twitter-bootstrap

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

JS 过滤数组的数组

我正在尝试过滤数组的数组。

我已经搜索了 SO 的答案,但我遇到的所有问题都与我的不匹配(对象数组或未嵌套的简单数组或格式不同等......)

在此输入图像描述

将值存储在数组中后,它们看起来像这样:

[[Paris, One ONE, Boss, Wed Mar 01 00:00:00 GMT+01:00 2017, ], [Paris, Two TWO, Temp, Sat Jul 01 00:00:00 GMT+02:00 2017, ], [Paris, Three THREE, Employee, Sat Sep 01 00:00:00 GMT+02:00 2018, ], [Paris, Four FOUR, Intern, Thu Nov 01 00:00:00 GMT+01:00 2018, ], [Paris, Five FIVE, N.A., Sat Dec 01 00:00:00 GMT+01:00 2018, ], [Paris, Six SIX, Director, Tue Jan 01 00:00:00 GMT+01:00 2019, ], [Paris, Seven SEVEN, Director, Fri Jan 01 00:00:00 GMT+01:00 …
Run Code Online (Sandbox Code Playgroud)

javascript google-apps-script

5
推荐指数
2
解决办法
4253
查看次数

material-ui react.js 中带有评级值的错误

我有 3 组不同的评分,它们都需要独立。错误是当单击其中一个评级时,只有第一组(首先呈现)评级发生变化。这意味着所有不同的评级集之间似乎都有联系。

在此处输入图片说明

与此错误相关的主要部分是名为 AssetName 的方法。

function AssetName(props) {
  let localAssetName = [];
  let streamHolder = [];
  let holder = [];

  localAssetName.push("Asset 1");
  localAssetName.push("Asset 2");
  localAssetName.push("Asset 3");
  localAssetName.push("Asset 4");
  localAssetName.push("Asset 5");
  localAssetName.push("Asset 6");

  // this.setState({ assetNameAr : localAssetName});
  // this.setState({assetTest: true})
  props.parentCallback(localAssetName);
  let displasset = function displfcn() {
    for (let i1 = 0; i1 < localAssetName.length; i1++) {
      holder.push(
        <Grid container spacing={10}>
          <Grid item>
            <Box> {localAssetName[i1]}</Box>
          </Grid>
          <Grid item p={10} ml={10}>
            {/* Technical Expertise */}
            {/* <AssetLoop len ='1'/> */} …
Run Code Online (Sandbox Code Playgroud)

javascript web reactjs material-ui

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

适合容器中的旋转图像 jQuery css

我开发了这个脚本来通过单击按钮来旋转图像......

问题

它旋转得很好,但问题是,一旦图像旋转 90 度或 270 度,它就不再适合主容器......

我希望它旋转 90/270 度后就能与容器配合。

$(document).ready(function() {
  var degrees = 0;
  $("button").click(function rotateMe(e) {
    degrees += 90;
    //$('.img').addClass('rotated'); // for one time rotation
    $(".content").css({
      'transform': 'rotate(' + degrees + 'deg)',
      '-ms-transform': 'rotate(' + degrees + 'deg)',
      '-moz-transform': 'rotate(' + degrees + 'deg)',
      '-webkit-transform': 'rotate(' + degrees + 'deg)',
      '-o-transform': 'rotate(' + degrees + 'deg)'
    });
  })
});
Run Code Online (Sandbox Code Playgroud)
.rotated {
  transform: rotate(90deg);
  -ms-transform: rotate(90deg);
  -moz-transform: rotate(90deg);
  -webkit-transform: rotate(90deg);
  -o-transform: rotate(90deg);
}

.img {
  transition: all 0.5s …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

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

无需单击按钮即可调用js函数

问题在于,在单击按钮3之前调用了该函数。我该如何解决该错误,以及为什么button3不起作用?o_O在该代码中找不到我的失败。谢谢

Buttons()

function Buttons() {
  var buttonDivs = document.getElementById('Buttons')
  var buttons = document.createElement('input')
  buttons.setAttribute('type', 'button')
  buttons.setAttribute('name', 'button3')
  buttons.setAttribute('value', 'button3')
  buttons.setAttribute('id', 'btn');
  buttons.onclick = function3('button3');
  buttonDivs.appendChild(buttons)
}

function function3(something) {
  console.log('hello' + something)
}
Run Code Online (Sandbox Code Playgroud)
<div id="Buttons">
  <button onclick="function3('test1')">Button1</button>
  <button onclick="function3('test2')">Button2</button>
  <br><br><br><br>
</div>
Run Code Online (Sandbox Code Playgroud)

javascript button

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

Nodejs同步for循环

有人可以帮助我以同步方式运行以下循环吗?由于下面的代码是异步执行的,值arra总是返回 null。

var arra=[];
//Query doctors collection and get necessary details           
for (i = 0; i <arr.length; i++) {
    var docregistrationnumber = arr[i].docregistrationnumber
    var registrationAuthority = arr[i].docregistrationauthority                
    doctorData.getDoctorByRegNumber(docregistrationnumber,registrationAuthority,function(data){
        console.log(JSON.stringify(data))  
        arra.push(data)                
    })
} 
console.log(arra) 
Run Code Online (Sandbox Code Playgroud)

javascript node.js promise

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

检查除一个以外的所有对象值

我有一个 JavaScript.The 对象看起来像

{date: "2019-10-03", hello: 0, yo: 0, test: 0}
Run Code Online (Sandbox Code Playgroud)

我可以检查对象中的所有值是否==0都不是日期吗?

我不确定如何进行编码。

javascript arrays jquery json javascript-objects

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