jQuery 模板疑问:
关于 jQuery 模板,Rick Strahl 有一篇出色的文章解释了功能在这里。在解释过程中,他接着说 jQuery 在某种程度上支持模板化
模板被合并到 本例中的数组。当结果 是一个数组,模板是 自动应用于每个 数组项。如果你传递单个数据 项目 – 比如股票报价 – 模板的工作方式完全相同 但仅应用一次。模板 还可以访问 $data 项 提供当前数据项和 有关模板的信息是 目前正在执行。这使得 可以将上下文保留在 模板本身的上下文以及 还可以从父级传递上下文 模板到子模板是 非常强大。
我不太明白这是什么意思。有人可以帮助我理解这一点吗?
With reference to jQuery templating, Rick Strahl has an excellent writeup explaining with functionality over here. During the course of explanation he goes on to say that jQuery supports templating in a way
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.
I didn’t quite understand what this means. Can someone help me understand this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它类似于asp.net中的asp:Repeater。将数据数组放入其中,控件根据数组中的每个项目填充自身。在本例中,它只是使用 jquery + jQuery Data Link。
所以不要使用
更改为
its similar asp:Repeater in asp.net. Throw array of data into it, the control populate itself based on each item in array. In this case, it just using jquery + jQuery Data Link.
so instead of use
change to
他正在谈论嵌套模板;允许一个模板在另一个模板中使用。然后,他继续解释如何将父模板的上下文传递给嵌套在其中的子模板。
模板需要传递给它们的变量才能显示动态信息。这些被传递的变量通常以数组或散列/字典的形式传递,通常被称为“上下文”。正如 Rick 的文章提到的,您可以在父模板中拥有主上下文,但也可以将上下文传递给子模板。
He's talking about nesting templates; Allowing one template to be used inside another template. He then goes on to explain how the context for the parent template can be passed to these child templates nested inside it.
Templates need variables passed to them in order to display dynamic information. These variables being passed, usually in an array or hash/dictionary, are often referred to as a "context". As Rick's article mentions, you're able to have a main context in your parent template, but also pass context to the child template.