Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【kit.template】简易模板用法 #12

Open
Kelichao opened this issue Feb 23, 2017 · 0 comments
Open

【kit.template】简易模板用法 #12

Kelichao opened this issue Feb 23, 2017 · 0 comments

Comments

@Kelichao
Copy link
Owner

Kelichao commented Feb 23, 2017

数据源是数组

var html = '<div class={{name}}>{{type}}</div><div>{{age}}</div><br>';
var value = [{
		age:111,
		name:222,
		type: "ok"
	},
	{
		age:444,
		name:555,
		type: ""
	}
];

// 简易模板
// str是模板字符串
// value是渲染数据的【数组】
// symbol是无数据展示的内容
var x = kit.template(html,value,"---");
console.log(x);
//"<div class=222>ok</div><div>111</div><br>
//<div class=555>---</div><div>444</div><br>"

数据源是对象

var html = '<div class={{name}}>{{type}}</div><div>{{age}}</div><br>';
var value = {
		age:111,
		name:222,
		type: "ok"
	};

// 简易模板
// 需要传入一个数组
// str是模板字符串
// value是渲染数据的【数组】
// symbol是无数据展示的内容
var x = kit.template(html,value,"---");
console.log(x);
//"<div class=222>ok</div><div>111</div><br>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant