帝国cms 文章列表api实现过程
1、系统-管理菜单-扩展菜单-新建:文章列表API接口
2、插件-找到菜单-点击-菜单名称:课程表列表api
链接地址:plugins/api/index.php
金刚模式链接
3、刷新:插件-找到菜单-点击-菜单名称:课程表列表api
建模块:kcb 课程表 课程表
建控制器listinfo 代码如下
<?php
defined("api_m") or exit;
$p = $api->param('page' , 1 , 'intval'); //页码
if($p==0)
{
$p=1;
}
$classid = $api->param('classid' , 88 , 'intval'); //classid
$w = "classid = ".$classid;
$l = $api->param('limit' , 10 , 'intval');
$table = "ecms_xk"; //表
$rulelist = $api->select($table , $field = 'id,title,ftitle,titlepic,onclick,newstime' , $where = $w , $limit = $l , $page = $p , $orderby = 'newstime desc');
//构造输出数组
$res = array(
"success" => true,
"data" => $rulelist
);
//输出json数据
$api->json($res);
?>
预览:获得接口地址http://www.uclass.top:8085/e/extend/api/index.php?m=kcb&c=listinfo
可以添加page参数http://www.uclass.top:8085/e/extend/api/index.php?m=kcb&c=listinfo&page=3
在mui调用和遍历Jason数据
<script>
mui.init();
var url = "http://www.uclass.top:8085/e/extend/api/index.php?m=kcb&c=listinfo";
mui.ajax(url,{
data: {
'type': 1,
's': "喜欢你",
'limit': 10
},
dataType:'json',//服务器返回json格式数据
type:'post',//HTTP请求类型
timeout:10000,//超时时间设置为10秒;
success:function(data){
console.log(JSON.stringify(data));
var songs=data.songs;
var list = document.getElementById("list");
var fragment = document.createDocumentFragment();
var li;
mui.each(songs,function(index,item){
var id = item.id,
name = item.title,
author = item.username,
picUrl = "http://www.uclass.top:8085"+item.titlepic,
audio = item.titleurl;
li = document.createElement('li');
li.className = 'mui-table-view-cell mui-media';
li.innerHTML = '<a class="mui-navigate-right" id='+ id +' data-audio='+ audio +'>'+
'<img class="mui-media-object mui-pull-left" data-lazyload="'+picUrl+'">'+
'<div class="mui-media-body">'+name+
'<p class="mui-ellipsis">'+author+'</p>'+
'</div>'+
'</a>';
fragment.appendChild(li);
})
list.appendChild(fragment)
mui(document).imageLazyload({
placeholder: '../img/60x60.gif'
});
},
error:function(xhr,type,errorThrown){
//异常处理;
console.log(type);
}
});
//列表点击事件
mui("#list").on('tap','li a',function(){
var id = this.getAttribute('id');
var audio = this.getAttribute('data-audio');
//打开详情页面
mui.openWindow({
url:'music.html',
id:'music.html',
extras:{
musicId:id,
audioUrl:audio ,
}
});
});
</script>