小编Tim*_*ann的帖子

使用underscore.js findWhere函数时如何使用变量作为属性名?

我在查找如何在使用_.findWhere函数时在underscore.js中动态设置属性时遇到问题.

这是该函数的文档:

findWhere_.findWhere(list, properties) 
Run Code Online (Sandbox Code Playgroud)

查看列表并返回与属性中列出的所有键值对匹配的第一个值.

如果未找到匹配项,或者list为空,则返回undefined.

_.findWhere(publicServicePulitzers, {newsroom: "The New York Times"});
=> {year: 1918, newsroom: "The New York Times",
reason: "For its public service in publishing in full so many official reports,
documents and speeches by European statesmen relating to the progress and
conduct of the war."}
Run Code Online (Sandbox Code Playgroud)

在文档中建模示例,我想设置属性以动态搜索:

 var publicServicePulitzers = [
    {"newsroom":"The New York Times", "year":2013 },
    {"newsroom":"The Los Angeles Times", "year":2012 }
 ];

var myprop = 'newsroom';
_.findWhere(publicServicePulitzers, { myprop : "The New York Times"});
Run Code Online (Sandbox Code Playgroud)

结果未定义.

我也尝试过: …

underscore.js

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

Chartjs:如何在y轴上仅显示最大值和最小值

我想覆盖Chart JS中的漂亮数字算法,并在y轴上只显示两个标签(或刻度):值的最大值和最小值.这些值都是浮点数.我看到回调函数(yAxis.ticks.callback)已经找到了勾号,所以我不认为这是做这件事的地方.任何帮助,将不胜感激.

javascript chart.js chartjs-2.6.0

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

ChartJS:在鼠标悬停时在图表上的数据点绘制垂直线

我无法弄清楚当使用Chart JS将鼠标悬停在数据点上时,如何在折线图上绘制垂直线.我希望该线保持在图表矩形的范围内,以便它不会延伸到刻度区域.任何帮助,将不胜感激!

javascript chart.js chartjs-2.6.0

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