我使用带有es6和babel的PolymerTS https://github.com/nippur72/PolymerTS#property装饰器。
当我尝试设置用@property
装饰器
Uncaught TypeError: Cannot assign to read only property 'suggestionSelected' of object '#<suggestions-selector>'(…)
偶readonly
标志为假
一些代码示例,但所有类似情况下的错误相同
@property({type: Number, value: -1})
suggestionSelected;
onInputKeypress(e) {
if (keycode(e) === 'down') {
e.preventDefault();
this.$.suggestions.selectNext();
} else if (keycode(e) === 'up') {
e.preventDefault();
this.$.suggestions.selectPrevious();
} else if (keycode(e) === 'enter') {
this.fire('search', {query: this.$.input.value});
this.suggestions = [];
this.suggestionSelected = -1;
} else {
this.suggestionSelected = -1; // error here
this.fetchSuggestions();
}
}
```