[英]Kendo UI Template not works
We are trying to render some remote json data from AJAX to Kendo UI template but without success. 我们正在尝试将一些远程json数据从AJAX渲染到Kendo UI模板,但没有成功。
<div id="example"></div>
$(document).ready(function() {
function getCookie(key) {
var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
return keyValue ? keyValue[2] : null;
}
var token = getCookie('_access_token');
var userDS = null;
jQuery.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "url",
dataType: "json",
headers: { Authorization: "Bearer " + token },
success: function (data) {
userDS = data;
var template = kendo.template("<div>#= name #</div>");
var data = JSON.stringify(userDS);
var result = template(data);
$("#example").html(result);
console.log(data);
},
error: function (result) {
alert("Error");
}
});
});
We are retriving the data without issue - it's tested with console.log(data);
我们正在毫无问题地检索数据-已通过
console.log(data);
进行了测试console.log(data);
and the result is: 结果是:
{
"id": 1,
"name": "Full Name",
"username": "Username",
"email_verified_at": null,
"created_at": "2018-10-15 14:03:15",
"updated_at": "2018-10-15 14:03:15"
}
Anyone can advice/help please? 任何人都可以提供建议/帮助吗?
Why do you use JSON.stringify
? 为什么使用
JSON.stringify
? It turns your object into a string. 它将您的对象转换为字符串。 Of course, the template engine cannot extract any values from it.
当然,模板引擎无法从中提取任何值。 Simply remove the line and you get your template.
只需删除该行,即可获得模板。
Simplified working example: 简化的工作示例:
<div id="example"></div>
<script type="text/javascript">
$(document).ready(function() {
var data = {
"id": 1,
"name": "Full Name",
"username": "Username",
"email_verified_at": null,
"created_at": "2018-10-15 14:03:15",
"updated_at": "2018-10-15 14:03:15"
};
var template = kendo.template("<div>#= name #</div>");
var result = template(data);
$("#example").html(result);
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.