且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AMP小胡子和数学

更新时间:2023-12-01 08:12:10

如果要在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).