douwuli4512 2019-04-18 18:14
浏览 75

是否可以将表数据与数组匹配,并将其转换为PHP中的html链接

I currently have a jQuery script that matches the values from my table to an array to find a corresponding url and output it as html. It works fine however I would like to keep my array private (so that all of the data cannot be viewed in the inspector if a match isn't found) and from my understanding that cannot be done with javascript. I am already using PHP to dynamically create the table so I was wondering whether this would be possible.

var profiles = [{
    "name": "Susie",
    "link": "www.google.com"
  },
  {
    "name": "John",
    "link": "www.yahoo.com"
  }
];
$(document).ready(function() {
  $('tr').each(function(index, item) {
    var value = $(item).find('td').eq(1).text();
    var exist = profiles.filter(c => c.name == value);
    if (exist.length > 0) {

      var link = exist[0].link;

      $(item).find('td').eq(1).html("<a href='" + link + "'>" + value + "</a>");
    }
  })
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <thead>
    <th>#</th>
    <th>Name</th>
  </thead>
  <tbody>
    <tr>
      <td>1
        <td>Susie</td>
    </tr>
    <tr>
      <td>2
        <td>John</td>
    </tr>
  </tbody>

I was thinking of using a JSON file to store the data but I am not sure where to go from there.

$data = '{"Susie": "www.google.com","John": "www.yahoo.com"}';
$array = json_decode($somedata, TRUE);
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题