gpt4 book ai didi

jQuery模板疑问:

转载 作者:行者123 更新时间:2023-12-01 04:28:35 25 4
gpt4 key购买 nike

关于 jQuery 模板,Rick Strahl 有一篇出色的文章解释了功能 over here 。在解释过程中,他接着说 jQuery 在某种程度上支持模板

The template is merged against an array in this example. When the result is an array the template is automatically applied to each each array item. If you pass a single data item – like say a stock quote – the template works exactly the same way but is applied only once. Templates also have access to a $data item which provides the current data item and information about the tempalte that is currently executing. This makes it possible to keep context within the context of the template itself and also to pass context from a parent template to a child template which is very powerful.

我不太明白这是什么意思。有人可以帮助我理解这一点吗?

最佳答案

它类似于asp.net中的asp:Repeater。将数据数组放入其中,控件根据数组中的每个项目填充自身。在本例中,它只是使用 jquery + jQuery Data Link。

所以而不是使用

for(looping)
$("body").append("<div>"+sometext+"</div>");

更改为

<script id="stockTemplate" type="text/x-jquery-tmpl">    
<div>${objName}</div>
</script>
...and
$("#somediv").link(someJSON);

关于jQuery模板疑问:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4418184/

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