Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript if语句的模板语法_Javascript_Html_Templates - Fatal编程技术网

Javascript if语句的模板语法

Javascript if语句的模板语法,javascript,html,templates,Javascript,Html,Templates,我有一个关于模板语法和解析对象的快速问题。因此,我有一个对象,我想有条件地打印它,如下所示: {'paragraph':'Some important text that you want printed.'}, /** * Prints the text object specified. * @param textToPrint All of the items you want rendered on the page. */ {template .printText}

我有一个关于模板语法和解析对象的快速问题。因此,我有一个对象,我想有条件地打印它,如下所示:

{'paragraph':'Some important text that you want printed.'},
 /**
  * Prints the text object specified.
  * @param textToPrint All of the items you want rendered on the page.
  */
 {template .printText}
    {foreach $textItem in textToPrint}
      {if $textItem[0] is 'paragraph'}          //THIS IS THE LINE IN QUESTION
         {call .paragraph}
            {param paragraph: $textItem[0] /}
         {/call}
      {else}
         {call .list}
            {param listItem: $textItem[0] /}
         {/call}
      {/if}
    {/foreach}
  </ul>
 {/template}
我想知道我怎样才能对“段落”的第一个论点进行检验。我希望根据该参数有条件地调用子模板。比如说

{'list':['item 1', 'item 2']}
我想尝试这样做:

{'paragraph':'Some important text that you want printed.'},
 /**
  * Prints the text object specified.
  * @param textToPrint All of the items you want rendered on the page.
  */
 {template .printText}
    {foreach $textItem in textToPrint}
      {if $textItem[0] is 'paragraph'}          //THIS IS THE LINE IN QUESTION
         {call .paragraph}
            {param paragraph: $textItem[0] /}
         {/call}
      {else}
         {call .list}
            {param listItem: $textItem[0] /}
         {/call}
      {/if}
    {/foreach}
  </ul>
 {/template}
/**
*打印指定的文本对象。
*@param textToPrint您希望在页面上呈现的所有项目。
*/
{template.printText}
{textToPrint中的foreach$textItem}
{如果$textItem[0]是“段落”}//这是有问题的行
{调用.段落}
{param段落:$textItem[0]/}
{/call}
{else}
{call.list}
{param listItem:$textItem[0]/}
{/call}
{/if}
{/foreach}

{/template}

有人知道这样做的语法吗?谢谢

好吧,我想应该是这样的:

{if $textItem  == 'paragraph'}