Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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
Amp html 如何在amp列表模板中执行字符串操作?_Amp Html - Fatal编程技术网

Amp html 如何在amp列表模板中执行字符串操作?

Amp html 如何在amp列表模板中执行字符串操作?,amp-html,Amp Html,我可以使用amp-bind更新锚定的[href]。但是,如果我在amp列表模板中包含相同的锚,则当应用模板时,[href]会出现损坏(它由原始位置和URI编码预先设置)。值得注意的是,字符串周围缺少单引号,导致表达式编译错误 在下面的示例中,amp list之前的链接在按下按钮时会很好地更新,而由amp list模板生成的链接会被损坏。有趣的是,模板中的锚仍然读得很好;只有在应用了模板之后,[href]才会损坏 锚定内模板: <a href="https://amp-test/" [hre

我可以使用
amp-bind
更新锚定的
[href]
。但是,如果我在
amp列表
模板中包含相同的锚,则当应用模板时,
[href]
会出现损坏(它由原始位置和URI编码预先设置)。值得注意的是,字符串周围缺少单引号,导致表达式编译错误

在下面的示例中,
amp list
之前的链接在按下按钮时会很好地更新,而由
amp list
模板生成的链接会被损坏。有趣的是,模板中的锚仍然读得很好;只有在应用了模板之后,
[href]
才会损坏

锚定内模板:

<a href="https://amp-test/" [href]="path ? 'https://amp-test/' + path.split(' ').join('-') : 'https://amp-test/'">{{linkName}}</a>
index.html


amp列表中的amp绑定
body{-webkit动画:-amp start 8s steps(1,end)0s1 normal tweet;-moz动画:-amp start 8s steps(1,end)0s1 normal tweet;-ms动画:-amp start 8s steps(1,end)0s1 normal tweet}@-webkit关键帧-amp start{从{可见性:隐藏}到{可见性:可见}}@-moz关键帧-amp start{from{可见性:隐藏}
更新



尝试使用来操纵帖子的AMP内容。为此,您应该避免禁用的URL协议或表达式,否则AMP验证程序将失败

关于amp列表中的amp绑定操作,您可能想检查一下,其中提到允许绑定到
组件和属性,其行为如下:

如果表达式是字符串,则从字符串URL获取并呈现JSON。如果表达式是对象或数组,则呈现表达式数据


我不知道您为什么建议使用消毒;我从AMP HTML文档开始,而不是将页面从HTML转换为AMP HTML。您指向(并引用)的文档仅引用AMP列表属性[src],而不是AMP列表模板中的元素属性。
<a href="https://amp-test/" [href]="https://amp-test/path%20?%20%27https://amp-test/%27%20+%20path.split(%27%20%27).join(%27-%27)%20:%20%27https://amp-test/%27" target="_top" class="i-amphtml-error">one path</a>
{
    "items": [
        { "linkName": "one path" },
        { "linkName": "two path" }
    ]
}
<!doctype html>
<html ⚡>
<head>
    <title>amp-bind in amp-list</title>
    <meta charset="utf-8">
    <script async src="https://cdn.ampproject.org/v0.js"></script>
    <script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
    <script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
    <script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.1.js"></script>
    <link rel="canonical" href="https://cmphys.com/">
    <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
    <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>

    <style amp-custom>
    </style>
</head>
<body>
    <button on="tap:AMP.setState({path: 'relative path'})">Update</button>

    <hr>
    <p>
        <a href="https://amp-test/" [href]="path ? 'https://amp-test/' + path.split(' ').join('-') : 'https://amp-test/'">link</a>
    </p>

    <hr>
    <amp-list id="myList" class="list" layout="fixed" width="200" height="100" src="/results.json">
        <template type="amp-mustache">
            <a href="https://amp-test/" [href]="path ? 'https://amp-test/' + path.split(' ').join('-') : 'https://amp-test/'">{{linkName}}</a><br>
        </template>
    </amp-list>

</body>
</html>