Dom聚合物if-else条件不起作用

问题描述 投票:0回答:1

以下为工作内容:

  • 我有一个DOM-Polymer-HTML-Template代码,当我单击“更多信息”链接时会弹出一个窗口

  • 我有4个不同的国家,分别存储在从我的后端代码返回的'country'值中的USA,IN,CA和AUS。] >>

  • 当用户选择IN,CA和AUS作为“国家”时,应该在模板中执行info_generic.html。

  • 当用户选择美国作为“国家”时,应该在模板中执行info_usa.html。

    下面是代码:

<dom-module>
    <template>
        <div>
            <template is="dom-if" if="[[ selectedCountry('USA') ]]">
                <a onclick="popup('USA Info', 500, 300)" href="info_usa.html" target="_blank">More Info</a>
            </template>

            <template is="dom-if" if="[[ !selectedCountry('USA') ]]">
                <a onclick="popup('Info', 500, 30)" href="info_generic.html" target="_blank">More Info</a>
            </template>
        </div>
    </template>

    <script>
        Polymer({
            is: 'info',
            selectedCountry: function(country) {
                return country;
            }
            popup: function(href, title, width, height) {
                this.width = width;
                this.height = height;
            }
        });
    </script>
</dom-module>

info_generic.html

<div>
    <p>Contact 1800-232-1800 for More information</p>
</div>

info_usa.html

<div>
    <p>Contact 1800-233-1800 for More information</p>
</div>

问题:我正在尝试对dom-module / template中的if条件进行否定和否定,这不起作用

任何人都可以帮忙吗?

提前感谢

以下是有效的:我有一个DOM-Polymer-HTML-Template代码,单击“更多信息”链接时会弹出一个窗口,我有4个不同的国家,分别存储在美国,美国,加拿大和美国。 ..

我没有遵循您要使用的代码。

您没有在Polymer中使用onclick,而是“点击”,但实际上对popup并没有做任何事情。如果您有类似this.width = width的内容,我会理解,您可以在<info>元素中设置属性,但现在您只是将值设置为其自身。

对于selectedCountry,您发送字符串作为参数('USA')。然后,您返回此字符串,该字符串始终为dom-if true。因此,第一个dom-if总是会发生。该参数需要是一个变量,然后return语句应类似于country == 'USA'

dom polymer angular2-template
1个回答
0
投票

我没有遵循您要使用的代码。

您没有在Polymer中使用onclick,而是“点击”,但实际上对popup并没有做任何事情。如果您有类似this.width = width的内容,我会理解,您可以在<info>元素中设置属性,但现在您只是将值设置为其自身。

对于selectedCountry,您发送字符串作为参数('USA')。然后,您返回此字符串,该字符串始终为dom-if true。因此,第一个dom-if总是会发生。该参数需要是一个变量,然后return语句应类似于country == 'USA'

© www.soinside.com 2019 - 2024. All rights reserved.