我这样命名我的模板:
$("#ChangeCurrentCycleDiv").html(
$("#UpdateTemplate").render(CurrentCyclefields,
{ButtonName: "btnChangeCycle",
Titel: "Change Current Cycle",
FormID: "ChangeCurrentCycleForm",
PanelSize: "ms-Panel ms-Panel--Max" },
true)
);
这很好用,但现在我添加了"PanelSize“参数,该参数有时使用,有时不使用。因此,在我的模板中,我尝试这样做:
<div {{if {{:~PanelSize}} }} class={{:~PanelSize}} {{else}}class="ms-Panel ms-Panel--xxl"{{/if}}>
但是无论我使用哪种变体,它都不起作用(错误的语法错误)。
执行此操作的正确语法是什么?因此,如果参数为send,则使用该参数。否则,将使用默认值。
谢谢
发布于 2018-06-07 08:43:41
{{if}}
的语法为{{if ~PanelSize}} .... {{else}} ... {{if}}
所以在你的情况下,它将是
<div {{if ~PanelSize}}class="{{:~PanelSize}}"{{else}}class="ms-Panel ms-Panel--xxl"{{/if}}>
或者更好,也许是:
<div class="{{if ~PanelSize}}{{:~PanelSize}}{{else}}ms-Panel ms-Panel--xxl{{/if}}">
或者,您可以使用三元表达式:
<div class="{{:~PanelSize?~PanelSize:'ms-Panel ms-Panel--xxl'}}">
或者使用||
甚至更简单
<div class="{{:~PanelSize||'ms-Panel ms-Panel--xxl'}}">
如果使用的是JsViews数据链接,则可以改用数据链接表达式:
<div data-link="class{:~PanelSize||'ms-Panel ms-Panel--xxl'}">
https://stackoverflow.com/questions/50722659
复制相似问题