gpt4 book ai didi

javascript - jsrender 模板不会渲染,有什么想法吗?

转载 作者:行者123 更新时间:2023-12-03 12:45:42 24 4
gpt4 key购买 nike

谁能告诉我为什么这个模板无法渲染?

我像这样渲染它:

 var v = jQuery.url().param("id");
jQuery.ajax({
post: "POST",
url: "svc.asmx/FetchNewsDetail",
dataType: "text",
contentType: "application/json; charset=utf-8",
data: { 'id': v },
success: function (data) {

jQuery("#blog").append(jQuery("#newsSingleTemplate").render(data));
}
});

这是我通过 Web 方法(asp.net、asmx)收到的 json 字符串:

{"newsDetailId":1,"newsId":1,"newsItemTitle":"Make Your Reservations Before It\u0027s Too Late","newsItemDate":"\/Date(1400652000000)\/","newsItemBannerUrl":"img/news/bass_single_news.jpg","newsItemBannerAlt":"BASS Divisional","newsItemText":"Join us at the Noxon Reservoir in Trout Creek, Mont., for the 2014 B.A.S.S. Nation Western Divisional. This fishery is in the northwest corner of Montana, very close to Idaho and only a 2-hour drive to Canada. Montana has hosted B.A.S.S. Nation divisionals, but it has not hosted other levels of B.A.S.S. tournaments. Competitors will vie for the Western title May 21-23.","newsItemQuote":"I think what I like most about B.A.S.S. Nation divisionals is the opportunity to go to places that you don\u0027t often think of as well-known tournament destinations, such as Noxon in Montana and Lake Monroe in Indiana\"- Jon Stewart, director of the B.A.S.S. Nation"}{"d":null}

这是我的模板

            <script id="newsSingleTemplate" type="text/x-jsrender">
<article>
<section class="first-column">
<header>
<h2>{{:newsItemTitle}}</h2>
</header>
<div class="date">
{{:newsItemDate}}
</div>
<p>
<img src="{{url:newsItemBannerUrl}}" width="670" height="300" alt="{{:newsItemBannerAlt}}" />
<br />{{:newsItemText}}</p>
<div id="slogan">
<h1>{{:newsItemQuote}}</h1>
</div>
</section>
</article>
</script>

谢谢你的帮助!

最佳答案

已成功测试 a fiddle 。你的问题表述得不是很清楚。究竟是什么不起作用?您的模板适用于哪种上下文?您使用什么数据结构?

var template = $.templates("#newsSingleTemplate");

template.link("#result", data);

关于javascript - jsrender 模板不会渲染,有什么想法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23352862/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com