thinkphp与javascript数据交互
2022-07-28 14:14:58
155
{{single.collect_count}}

thinkphp查询出来的数组

控制器代码

$income = Db::name('table')->select();$this->assign('income',$income);

javascript代码

var arr = {:json_encode($income)};var total = new Array();var date = new Array();for(i=0;i<arr.length;i++){total.push(arr[i].total);date.push(arr[i].months);}

arr数组
在这里插入图片描述
total数组
在这里插入图片描述
date数组
在这里插入图片描述

thinkphp查找出来的数组进行遍历

{foreach $income as $v}<td class="total">{$v.total}</td>{/foreach}

划重点 标签要用class不能用id

<script>var arr = new Array();$(".total").each(function(){arr.push($(this).text());});console.log(arr);</script>

这样就可以将class为total的标签的值全部放到 arr数组中了
在控制台打印就可以看到arr数组中存的值了
在这里插入图片描述

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}