小编Fre*_*ars的帖子

Lo-Dash - 帮助我理解为什么_.pick不能像我期望的那样工作

这有效:

MyCollection.prototype.select = function (properties) {
   var self = this;

   return {
      where: function (conditions) {
         return _.chain(self.arrayOfObjects)
           .where(conditions)
           .map(function (result) {
              return _.pick(result, properties);
           })
           .value();
      }
   };
};
Run Code Online (Sandbox Code Playgroud)

它允许我像这样查询我的集合:

var people = collection
             .select(['id', 'firstName'])
             .where({lastName: 'Mars', city: 'Chicago'});
Run Code Online (Sandbox Code Playgroud)

我希望能够编写这样的代码,但是:

MyCollection.prototype.select = function (properties) {
   var self = this;

   return {
      where: function (conditions) {
         return _.chain(self.arrayOfObjects)
           .where(conditions)
           .pick(properties);
           .value();
      }
   };
};
Run Code Online (Sandbox Code Playgroud)

Lo-Dash文档将_.pick回调指定为"[callback](Function | ... string | string []):每次迭代调用的函数或要选择的属性名称,指定为单独的属性名称或属性名称数组." 这让我相信我可以提供属性数组,它将应用于arrayOfObjects符合条件的每个项目.我错过了什么?

javascript lodash

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

jQuery - 在鼠标悬停时更改同一类嵌套 div 的边框颜色

我的 html 包含一系列嵌套的 div,每个都有相同的类(“shell”)但有一个唯一的 id。

<div class="shell s01" id="blah">
    <!-- s01 content -->
    <div class="shell s02" id="bar">
        <!-- s02 content -->
        <div class="shell s03" id="wah">
            <!-- s03 content -->
        </div>

        <div class="shell s03" id="foo">
            <!-- s03 content -->
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我希望鼠标进入时div的边框颜色发生变化,但是当鼠标进入子div时它应该恢复到原来的颜色。下面的 jQuery 代码将边框颜色更改为蓝色,但不会在鼠标进入子 div 时将父 div 边框恢复为原始颜色 (#8E8DA2)。相反,当鼠标悬停在一个内部 div 上时,它和它的所有祖先都会被高亮显示。例如,如果将鼠标悬停在“wah”上,那么也会突出显示“blah”和“bar”。我希望“blah”和“bar”恢复到原来的边框颜色。

我知道当鼠标悬停在孩子上方时,它也会悬停在孩子的父母上方。但我不确定为什么下面的“父母”声明不能解决问题。

$('.shell').mouseover(function() {
    $(this).parent('.shell').css('border-color', '#8E8DA2');
    $(this).css('border-color', '#0000FF');
});

$('.shell').mouseout(function() {
    $(this).css('border-color', '#8E8DA2');
});
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?谢谢!

html jquery border-color

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

标签 统计

border-color ×1

html ×1

javascript ×1

jquery ×1

lodash ×1