【开发笔记】APP端通知详情功能demo

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012492764/article/details/60778380
HTML页面引入模板引擎:
//templete.js
String.formatmodel = function(str, model) {
      for (var k in model) {
            var re = new RegExp("{" + k + "}", "g");
            str = str.replace(re, model[k]);
      }
      return str;
};
(function($, exports) {
      //获取通知详情
      exports.getTzXq = function(){
            var update = new StringBuilder();
            update.append('<div class="mui-indexed-list-group">');
            update.append('<span class="tztop" style="font-size: large;"><strong>[{categoryName}]</strong>{bt}</span><br />');
            update.append('<label >发布部门:{fbbm}&nbsp;&nbsp;&nbsp; 发表于:{fbsjString}</label>');
            update.append('</div>');
            update.append('<div class="mui-card-content" style="margin-top :7px;">');
            update.append('<label >{content}</label>');
            update.append('</div>');
            return update.toString();
      }
}(mui, window.templete = {}));

通过Ajax获取json数据:
$.ajax({
type:"get",
url:appUrl+"/tzgg/tzggXqJson.app?ak="+ak+"&id="+id,
async:true,
dataType:'json',
success:function(data){
if(data){
var xq = document.getElementById("xq");
var tzxq = new StringBuilder();
var str = String.formatmodel(templete.getTzXq(), data);
tzxq.append(str);
xq.innerHTML = tzxq.toString();

var xq_fj = document.getElementById("xq_fj");
var tzxq_fj = new StringBuilder();
$.each(data.attach, function(i,fj) {//遍历获取的JSON数组data中的附件attach数组
console.log(JSON.stringify(fj))
var str1 = String.formatmodel(templete.getAttach(), fj); //调用模板templete.js
tzxq_fj.append(str1);
});
xq_fj.innerHTML = tzxq_fj.toString();
}
},
error:function(xhr,type,errorThrown){
//异常处理;
 mui.toast('网络连接失败,请重试!');
}
});

     

没有更多推荐了,返回首页