【发布时间】:2019-09-23 15:01:18
【问题描述】:
我正在尝试为我的每个搜索结果提供一个百分比匹配分数,例如 90% Match。
我还没有找到任何在 python 中编写函数的解决方案,所以我想知道是否有一种方法可以创建一些 Javascript 代码,它会自动分配一个从 100 到 50% 的随机值(以相反的顺序)根据列表的默认顺序 (1,2,3,4..) 到有序列表中的每个项目(这是我的搜索结果)。
html 的简单示例:
<ol class="ordered-list">
<li class="list-item"><\li> <!-- This item represent the 1st result -->
<li class="list-item"><\li> <!-- 2nd result -->
<li class="list-item"><\li> <!-- 3rd result -->
<li class="list-item"><\li> <!-- 4th result -->
<!-- Etc... -->
<\ol>
现在最终的预期结果应该是这样的:
- Title 1
Description...
*100% Match*
- Title 2
Description...
*92% Match*
- Title 3
Description...
*85% Match*
- Title 4
Description...
*56% Match*
PS;搜索结果并非都是手动添加的,它们都来自一个数据库和一个索引。
关于如何实现这一点的任何想法?
【问题讨论】:
-
您在使用其中任何一种吗? jQuery/反应
-
我没有使用 React,但如果 Jquery 可以做到这一点,我绝对愿意使用它!
标签: javascript python html list frontend