AMP小胡子和数学 [英] AMP Mustache and Math

查看:86
本文介绍了AMP小胡子和数学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用amp-list和amp-template从JSON文件中获取一些变量.我收集的变量之一是我需要向上或向下取整的数字.该数字通常显示为{{number}}.但是,我需要操纵这个数字使其成为一个整数.我不确定如何在该amp var上进行转换.任何帮助表示赞赏.

I am getting some variables from a JSON file using amp-list and amp-template. One of the variables I've gathered is a number that I need to round up or down. The number would normally be displayed as {{number}}. However, I need to manipulate this number to make it a whole number. I am not sure how to do the conversion on that amp var. any help is appreciated.

推荐答案

如果要在amp-list中显示数据,则可以使用amp-statemapsrc属性内进行四舍五入:/p>

If you're displaying data in an amp-list you can do the rounding inside the src attribute by using amp-state and map:

<amp-state id="myState" src="http://your-data.com/json">

<amp-list 
    ... 
    [src]="
        myState.myItems.map(item => {
            roundedValue: round(item.value),
            otherProperty: item.otherProperty
        })
    "> 
    ... 
</amp-list>

,然后在模板中使用roundedValue.

有关支持功能的列表,请参见此页面:

See this page for the list of supported functions:

https://www.ampproject .org/es/docs/reference/components/amp-bind#white-listed-functions

但是请记住,如果您的对象有很多字段,则可能会遇到AMP对属性内的表达式施加的表达式大小限制(它们不能执行超过50个IIRC操作,包括函数调用,数学运算,字段取消引用等).

But keep in mind that if your objects have a lot of fields you may run into the expression size limit that AMP imposes on expressions inside attributes (they can't perform more than 50 operations IIRC, including function calls, math operations, field dereferencing, etc).

这篇关于AMP小胡子和数学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆