polymer - 为什么我的 this._setPropertyName 函数不起作用?
问题描述
我有以下聚合物元素:
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/polymer/polymer-element.html">
<link rel="import" href="../shared-styles.html">
<link rel="import" href="../../bower_components/dfw-styles/dfw-styles.html">
<link rel="import" href="../../bower_components/paper-button/paper-button.html">
<link rel="import" href="../../bower_components/paper-menu-button/paper-menu-button.html">
<link rel="import" href="../../bower_components/paper-listbox/paper-listbox.html">
<dom-module id="baseline-policy-create">
<template>
<style include="dfw-styles">
:host {
display: block;
}
.top-button{
float : right;
}
</style>
<div class="outer-buttons">
<paper-menu-button horizontal-align="right" no-overlap="true" no-animations class="top-button">
<paper-button slot="dropdown-trigger" class="dropdown-trigger create-button btn-primary">
<iron-icon icon="menu"></iron-icon>
<span>Create Baseline Policy</span>
</paper-button>
<paper-listbox slot="dropdown-content" class="dropdown-content">
<template is="dom-repeat" items="{{_domains}}">
<paper-item on-tap="getDomainSchema">[[item.label]]</paper-item>
</template>
</paper-listbox>
</paper-menu-button>
</div>
</template>
<script>
class BaselinePolicyCreate extends Polymer.Element {
static get is() {
return 'baseline-policy-create';
}
static get properties() {
return {
_domains: {
type: Array,
value: [{'name':'Package', 'label':'Package'},
{'name':'Subscription', 'label':'Subscription'}] //TODO: is it possible to get these values from an API source
},
requestedDomain: {
type: String,
value : "",
notify : true,
readOnly : true
}
}
}
getDomainSchema(evt) {
console.info("Get the schema for the following domain:", evt.target.innerText);
console.log(this.requestedDomain);
this._setRequestedDomain(evt.target.innerText);
//this.requestedDomain = evt.target.innerText;
console.log(this.requestedDomain);
}
}
customElements.define(BaselinePolicyCreate.is, BaselinePolicyCreate);
</script>
</dom-module>
我一直在关注本关于数据绑定的教程:https ://www.tutorialspoint.com/polymer/polymer_data_system.htm
在示例中,prop-element 的代码有一个属性 myProp,其属性 readOnly 设置为 true。在 Onclick 函数中,它仍然能够使用 this._setMyProp() 更改属性的值,该值未在任何地方明确定义。
我想在我的代码中做同样的事情。也就是说,我想用这个方法设置requestDomain。我可以使用这条线进行设置:
this.requestedDomain = evt.target.innerText;
但要这样做,我不能将 readOnly 标志设置为 true。如果我使用 this._setRequestedDomain,我会收到一条错误消息,指出它不是函数。我是否在顶部缺少一些导入以使其正常工作,或者它可能已在 Polymer 2 中删除?
解决方案
我一直在测试你的代码,没关系。
You only will get the error "this.setRequestedDomain is not a function" if your property is set as readOnly = false.
Please, try again and tell me if its ok.
推荐阅读
- biztalk - TDDS 数据库引用旧服务器
- android - 使用 Dagger2 将适配器注入片段
- c# - C# AsyncEnumerable 运行/等待多个任务永远不会完成
- python - 如何使用 python IoT Hub Device SDK 从 iot 设备中检索完整的设备孪生
- javascript - 在反应渲染中调用格式化函数是不好的做法吗?
- reactjs - React 中的组件延迟加载
- reactjs - React 有没有办法多次执行渲染函数的一部分,而另一部分继续初始执行?
- c# - SQLite 错误 14:如果在根文件夹中,则“无法打开数据库文件”
- java - 无法使用 Gradle 编译 Java 库,可与 IDE 一起使用
- arrays - 如何在 ruby 中使用空行作为分隔符将字符串拆分为数组?