小编Gra*_*ier的帖子

使用jQuery隐藏动态元素的正确方法

我有一个div元素,我的代码将填充动态数量的链接.使用jquery,我想隐藏除第一个之外的所有链接.这就是我提出的并且它有效,我只是想知道这是否是最好的方法:

$("#panelContainer").each(function(n) {
  $(this).children().hide();
  $("#panelContainer a:first").show();
});
Run Code Online (Sandbox Code Playgroud)

jquery hide

10
推荐指数
2
解决办法
1886
查看次数

php中关联数组的前两个元素

我已经完成了最终目标,但也许有一种更优雅的方式来实现这一目标.

如果我有这样的数组:

$data = array(
    'wood' => 2,
    'metal' => 5,
    'plastic' => 3, 
);
Run Code Online (Sandbox Code Playgroud)

我想从$ data获得前2个键/值对(即金属:5和塑料:3).这是我想出的:

arsort($data);       //put values in order
reset($data);           //set pointer to first element
$first = each($data);    //assign first element to $first
array_shift($data); //remove first element from array
reset($data);           //set pointer to the new first element
$second = each($data); //assign the new first element to $second
Run Code Online (Sandbox Code Playgroud)

php associative-array

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

如何使用 winstonjs 3.2+ 生成与 splat 相同的输出

我一直在推迟将winstonjs从升级3.1.03.2.x,因为我无法让它以同样的方式处理额外的元数据。

例如,我在整个应用程序中都有日志消息,其中包括字符串和对象形式的元数据。在3.1.0此设置中,可以很好地创建我正在寻找的输出:

const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf, colorize } = format;

const formatStr = printf(info => {
  return `[${info.timestamp}] ${info.level}\t ${info.label} ${info.message} ${JSON.stringify(info.meta)}`
});

let logger = createLogger({
  transports: [new transports.Console({ level: 'info' })],
  format: combine(
    colorize({message: true, level: true}),
    timestamp({format: 'MMM D, YYYY HH:mm'}),
    format.splat(),
    formatStr
  )
});

logger.info('any message',{extra: true});
logger.info('simple', "one", "two",{extra: true});
Run Code Online (Sandbox Code Playgroud)

输出是这样的:

[Jan 3, 2020 14:36] info     undefined …
Run Code Online (Sandbox Code Playgroud)

logging node.js winston

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

标签 统计

associative-array ×1

hide ×1

jquery ×1

logging ×1

node.js ×1

php ×1

winston ×1