事件后输出amp-bind格式值

时间:2019-01-25 11:29:56

标签: amp-html

我正在尝试格式化数字值的输出以使其在amp-bind上更具可读性,但是,我看不到如何在event.output值上实现正则表达式?

目前,我有以下内容;

                <label class="form-title">
                    <span>How much do you need?</span>
                    <span [text]="[amount]">
                        £1500000
                    </span>
                </label>
                <input type="range"
                       name="amountSlider"
                       min="10000"
                       step="10000"
                       value="1500000"
                       max="3000000"
                       on="change: AMP.setState({ amount: '£' + event.value.replace('/\B(?=(\d{3})+(?!\d))/g', ',')})">

但是,这会导致错误;

%s %s amp-bind: Expression eval failed. [object String].replace is not a supported function.​​​

1 个答案:

答案 0 :(得分:0)

函数“替换”不是列入白名单的函数: https://www.ampproject.org/docs/reference/components/amp-bind#white-listed-functions

出于您的目的,也许是这样:

  

“ 12345678.1” .split(/ \ B(?=(?:\ d {3})+(?!\ d))/)。join(“,”)

     

“ 12,345,678.1”

因为“拆分”已列入白名单。警告:我没有在AMP页面上对其进行测试!