template.js的使用

文档地址:https://aui.github.io/art-template/zh-cn/docs/syntax.html

参考博客:https://blog.csdn.net/gao_xu_520/article/details/78594792
参考博客:https://blog.csdn.net/qq_33401924/article/details/53259631

在模板中运用三元运算符

 <b class="fl {
  {v.MatchWin==1?'win':''}}">{
  {v.ScoreA}}</b>

在模板中的 if elseif 语法的运用

 {
  {if v.MatchStatus == 1}}
 <em>未开始</em>
  {
  {else if v.MatchStatus == 2}}
  <em>进行中</em>
  {
  {else}}
    <em>已结束</em>
   {
  {if}}
 

在模板中template.helper, 用来处理模板中参数的函数

在这里插入图片描述

第一种情况:

//这里的script的id对应下面template的渲染区域,并且type必须是text/html

注:1.这里的 { {each result as value i}} ,i也可以写成index,代表索引号; value是每一项是value;
2. { {#value.img}},这种前面加#号的,表示 不编码输出,例这里这样写是因为后台取回来的img是含有img标签的了,所以直接输出就可以,不需要编码

$(function () {

$.ajax({
url:‘http://192.168.16.27:9090/api/getindexmenu’,
type:‘get’,
dataType:‘json’,
success:function (result) {
var html= template(‘template’,result);//这里的 template(‘template’,result)对应2步的script的id
console.log(result);
$(’#content’).append(html);//写法1
document.getElementById(“content”).innerHTML = html;// 写法2
}

})

});

第二种情况:
另一种情况,当取回来的数据是多组对象的形式,如下:(跟上面的对比就是一组数据跟多组数据)
var data={
0:{iNewsId: “1”, sTitle: “哈哈哈1”, iFrom: “22334”, sGameVersion: “”, sAuthor: “奇迹”},
1:{iNewsId

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值