开发者

Rendering of inner jquery-template depending on field value

开发者 https://www.devze.com 2023-03-18 16:50 出处:网络
Got next template in separate file section.htm: <h3>${Name}</h3> {{each Variables}} {{tmpl($data) Type}}

Got next template in separate file section.htm:

<h3>${Name}</h3>
{{each Variables}}
    {{tmpl($data) Type}}
    ${Type} | ${Name} |开发者_如何学编程 ${Value}
    <br/>
{{/each}}

I need to render different templates (stored in htm files too) depending on Type. For example, for Type equal to "MultilineText" - MultilineText.htm should be used. Something like: {{tmpl($data) "MultilineText"}}

I already got MultilineText.htm loaded, compiled and cached.

Content of MultilineText.htm:

${Name}<textarea>${Value}</textarea>

But this code doesnt work :(

Please help.

Thanks.


And the answer is {{tmpl($value) $.template[$value.Type]}}

$.template[some_template_name] - with this u can choose what template will be rendered some_template_name - name of template.

Notice that template should be loaded and compiled with $.tmpl before and have some_template_name name.


I just ran into the same issue. You can add a call back to compare variables via a callback function.

Take a look at my question: Conditionals in jQuery templates

0

精彩评论

暂无评论...
验证码 换一张
取 消