javascript - polymer 、模板不会评估 true 和绑定(bind)

标签 javascript html templates polymer web-component

使用 polymer ,我非常简单地尝试评估对象属性是否是特定值,如果是,则将truthy模板的内容绑定(bind)到dom。

我有:

<polymer-element name="template-elem">
  <template >
    <div>
    <template if={{response.data.type === "message"}}>
      <div>working</div>
    </template>
    </div>
  </template>
  <script>

    Polymer({
      response: {}, 
        ready: function(){
      this.response = {"data":{
        "type":"message",
        "detail":"default"
      }};
        },
    });
  </script>
</polymer-element>

也尝试过,==“消息”。如果要求评估 bool 表达式,模板会绑定(bind),并且 {{response.data.detail}} 显示正确的文本。我已经在两个单独的元素中尝试过此操作(从头开始),但问题仍然存在,任何人都可以告诉我我明显忽略了什么?

还尝试传递给辅助函数{{response | parseObj}},{{响应项| parseObj}},{{response.data 中的项目 | parseObj}} 并且该函数从未被调用。

最佳答案

您忘记了 if 属性值两边的引号。尝试一下

<template if="{{response.data.type === 'message'}}">

如果没有引号,浏览器 (Chrome) 会将此行解析为

<template if="{{response.data.type" =="=" 'message'}}=""></template>

关于javascript - polymer 、模板不会评估 true 和绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28260839/

相关文章:

Javascript setTimeout 不会触发延迟

javascript - 无法获取/Nodejs 错误

javascript - Node 为使用 Promise.all 和 .catch() 语句的 Mongoose 请求抛出 UnhandledPromiseRejectionWarning

html - 为什么 ":active"在 Gecko 框架内不能正常工作?

javascript - 测试套件无法运行 TypeError : Cannot read property 'default' of undefined

jquery - 通过 jQuery 将 CSS 应用于 Javascript 调用的 div?

html - Web 浏览器如何实现文本搜索?

c++ - 通过继承减少模板膨胀

c# - 如何在泛型类中初始化静态属性?

C++ 模板特化问题