1 Star 0 Fork 26

小徐同学/fasty

forked from Michael Yang/fasty 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test.html 3.05 KB
一键复制 编辑 原始数据 按行查看 历史
Michael Yang 提交于 2022-06-06 16:44 . update docs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>fasty</title>
<script src="./fasty.js"></script>
<script src="./test/jquery.min.js"></script>
</head>
<div style="display: none" id="text">jquery获取内容</div>
<body>
<script>
var template = "";
var data = {"title": "title test", "content": "content test..."};
var fasty = new Fasty({
share: {
name: "fasty",
sexString: function (v) {
return v === 0 ? '' : '';
}
}
});
template = "1.text";
console.log(fasty.render(template, data))
template = "2.{{~ var x = 100}} {{x}}";
console.log(fasty.render(template, data))
template = "3.{{\"hello world\"}}";
console.log(fasty.render(template, data))
template = '4.{{* "<div> hello world </div>"}}';
console.log(fasty.render(template, data))
template = '5.{{! "&lt;div&gt; hello world &lt;/div&gt;"}}';
console.log(fasty.render(template, data))
template = '6.{{~ var array = [1,2,3]}} {{~ for(item of array)}} ---item:{{item}}-- {{~end}}';
console.log(fasty.render(template, data))
template = '7.{{~ var array = ["aaa","aa.bb",title.length]}} {{~ for(item of array)}} ---item:{{item}}-- {{~end}}';
console.log(fasty.render(template, data))
template = '8.{{~ var array = ["aaa","aa.bb",title.length]}} {{~ for(item in array)}} ---item:{{item}}-- {{~end}}';
console.log(fasty.render(template, data))
template = '9.{{~ var array = ["aaa","aa.bb",title.length]}} {{~ for(var i=0;i<array.length;i++)}} ---item:{{array[i]}}-- {{~end}}';
console.log(fasty.render(template, data))
template = '10.{{~ for(var i=0;i< Object.keys(data).length;i++)}} ---item:{{Object.keys(data)[i]}}-- {{~end}}';
console.log(fasty.render(template, data))
template = '11.test function --- {{sexString(0)}} --- {{sexString(1)}} ';
console.log(fasty.render(template, data))
template = '12.{{~ var array = ["aaa","aa.bb"]}} ' +
'{{~ for(var i=0;i<array.length;i++)}} ' +
' ---item:{{array[i]}}-- ' +
' {{~ for( x of array[i])}}' +
' {{x}}-' +
' {{~end}}' +
'{{~end}}';
console.log(fasty.render(template, data))
template = '13.{{~ if (title == content)}} ' +
'>>aaa ' +
'{{~elseif (title.length === 10)}}' +
'>>>>bbbb' +
'{{~else}}' +
'>>>cccc' +
'{{~end}}';
console.log(fasty.render(template, data))
template = '14.{{~ var array = ["aaa","aa.bb",title.length],other1="aaa,cc,dd",other2=123,other3 = title.length}}' +
' {{~ for(var i=0;i<array.length;i++)}} ' +
'---item:{{array[i]}}-- ' +
'{{~end}}'+
'{{other1}} '+
'{{other2}} '+
'{{other3}} ';
console.log(fasty.render(template, data))
template = '15.{{ $("#text").text() }} ';
console.log(fasty.render(template, data))
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/xiaoxustudent/fasty.git
[email protected]:xiaoxustudent/fasty.git
xiaoxustudent
fasty
fasty
master

搜索帮助