代码之家  ›  专栏  ›  技术社区  ›  Nina Lisitsinskaya

如何动态地将新行添加到存储在AMP状态的字符串中?

  •  0
  • Nina Lisitsinskaya  · 技术社区  · 7 年前

    amp-state ,当用户按下按钮时。所以我试过这个:

    <script src="https://cdn.ampproject.org/v0.js"></script>
    <script src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
    
    <amp-state id="formState">
      <script type="application/json">
        {
          "message": "Some text"
        }
      </script>
    </amp-state>
    
    <textarea [text]="formState.message"></textarea>
    
    <button type="button"
      on="tap:AMP.setState({formState: {message: formState.message + '\nSome another text'} })">
      Button
    </button>

    \ 性格。所以我真的 Some text\nSome another text textarea .

    String.fromCharCode

    安培状态 ,关于用户交互?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Sven Liivak    7 年前

    定义换行符:

    <amp-state id="formState">
      <script type="application/json">
      {
        "message": "Some text",
        "newLine": "\n"
      }
      </script>
    </amp-state>
    

    然后:

     on="tap:AMP.setState({formState: {message: formState.message + formState.newLine + 'asdf'} })">