我现在正在处理这个问题6个小时,我似乎无法看到它。 所以这是index.html的片段:
%E9%BB%91%E7%9C%BC%E5%9C%88%E4%B8%8D%E8%A6%81%E5
dataArray(总是很好):
<flat-data-array availableModes="{{modes}}" id="dataArray"></flat-data-array>
<flat-strip-view availableModes="{{modes}}" id="flatViewer"></flat-strip-view>
现在出现了问题:
<link rel="import" href="../../bower_components/polymer/polymer.html">
<dom-module id="flat-data-array">
<script>
(function() {
'use strict';
Polymer({
is: 'flat-data-array',
properties: {
strips: {
type: Array,
notify: true,
observe: '_stripsChanged'
},
availableModes: {
type: Number,
notify: true,
observe: '_modesChanged'
},
socket: {
type: Object
}
}
,
_stripsChanged: function(newVal, oldVal) {
this.fire('flat-strip-array-changed',{ newValue: newVal, oldValalue: oldVal});
},
_modesChanged: function(newVal, oldVal) {
this.fire('flat-strip-mode-changed',{ newValue: newVal, oldValalue: oldVal});
alert("Changed");
},
ready: function() {
this.socket = io.connect('http://192.168.0.101:3000');
socket.on('flatCommand', function(data) {
console.log(data);
});
this.availableModes=15;
/*[
{
modeID: 65,
letter: "A",
name: "Singler Color"
}
];*/
}
});
})();
</script>
</dom-module>
由于index.html中的定义,我希望两个元素中的availableModes相同。但如果我输入:
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../elements/flat-list/flat-list.html">
<dom-module id="flat-strip-view">
<template>
<style>
:host {
display: block;
}
</style>
<flat-list
strips="{{strips}}"
id="flatList"
>
</flat-list>
</template>
<script>
(function() {
'use strict';
Polymer({
is: 'flat-strip-view',
properties: {
strips: {
type: Array,
notify: true,
observer: '_flatStripChanged'
},
availableModes: {
type: Number,
notify: false,
observer: '_flatModeChanged'
}
}
,
_flatModeChanged: function(newVal, oldVal) {
this.fire('flat-strip-view-mode-changed',{ newValue: newVal, oldValalue: oldVal});
alert("Event");
},
_flatStripChanged(newVal, oldVal) {
this.fire('flat-strip-view-array-changed',{ newValue: newVal, oldValalue: oldVal});
}
});
})();
</script>
</dom-module>
我得到15(完全没问题),但是当我输入时
documtent.getElementById('dataArray').availableModes
它说document.getElementById('flatViewer').availableModes
奇怪的是,之前有相同的另一个定义(事实上我只删除了它来追踪问题)并且工作并将值传递给了该隐的最后一个元素。我无法看到任何差异。
undefined
适用于&#34; strip&#34;在任何方向上都有任何元素......
答案 0 :(得分:2)
将属性availableModes
更改为available-modes
。
将属性名称映射到属性名称时:
属性名称将转换为小写属性名称。例如,属性
firstName
映射到firstname
。带有破折号的属性名称通过将每个破折号后面的字符大写,然后删除破折号来转换为camelCase属性名称。例如,属性
first-name
映射到firstName
。
Souce:https://www.polymer-project.org/1.0/docs/devguide/properties.html#property-name-mapping