Javascript Mustach正在返回以前的数据和新的
Im使用返回模板中的json数据,但当Im使用json响应生成$.ajax帖子时,Mustach将返回以前的响应数据和新的响应数据。我怎样才能防止小胡子有以前的数据并且只返回一次响应 剧本 模板 你不应该使用:Javascript Mustach正在返回以前的数据和新的,javascript,json,mustache,Javascript,Json,Mustache,Im使用返回模板中的json数据,但当Im使用json响应生成$.ajax帖子时,Mustach将返回以前的响应数据和新的响应数据。我怎样才能防止小胡子有以前的数据并且只返回一次响应 剧本 模板 你不应该使用: $('#newpost').html(rendered); 而不是使用.prepend?这将在旧HTML之前添加新HTML,而不是替换它 编辑:聊天结束后,问题似乎不是来自胡须,而是来自一个奇怪的多PHP调用。胡子在这里看起来不错。我真的不明白问题所在,如果你有相同的数据来输入模板,那
$('#newpost').html(rendered);
而不是使用.prepend?这将在旧HTML之前添加新HTML,而不是替换它
编辑:聊天结束后,问题似乎不是来自胡须,而是来自一个奇怪的多PHP调用。胡子在这里看起来不错。我真的不明白问题所在,如果你有相同的数据来输入模板,那是因为你发送了相同的数据。尽管如此,你可以使用handlebar.js,这是对Mustache.js的升级:你正在用.htmlended代替旧的,在facebook上发布类似帖子,当我发送$.ajax请求时,墙会用以前的帖子更新。因此,我发布1,返回1,我发布2,返回1和2,等等。这是在替换帖子,而不是将其添加到上一篇文章的顶部,脚本在替换前几秒钟显示上一篇文章。我使用了append和prepend,这与数据解析是一样的。不是我把它发给谁我不认为它来自你的模板,它上面没有循环。唯一的循环是,它用于附件,但它不会复制完整的HTML两次。
<script id="template" type="x-tmpl-mustache">
<div class="panel panel-white">
<div class="panel-heading">
<label>UserID: {{ userid }}</label>
<span class="help-block">{{ date_created }}</span>
</div>
<div class="panel-body">
<div class="well-white well-sm">{{ post_text }}</div>
</div>
<div class="panel-footer">
<div id="attachmentlist">
{{ #attachments }}
<p>{{ filename }} ({{ filetype }})</p>
{{ /attachments }}
</div>
<br>
<div class="comment-textarea">
<form name="commentform">
<div class="comment-box media">
<a id="comment-box-a" class="pull-left" href="#">
<img class="media-object" src="source/images/nophoto.png" alt="...">
</a>
<div class="media-body form-group">
<textarea id="comment-box-msg" name="postMessage" class="form-control" row="1" placeholder="Write a comment..."></textarea>
</div>
<button id="comment-box-btn-post" class="btn btn-primary btn-sm pull-right" aria-hidden="true" type="button">Δημοσίευση</button>
</div>
</form>
</div>
</div>
</div>
</script>
$('#newpost').html(rendered);