Browse Source

Add rerender method in TraitView

pull/2190/head
Artur Arseniev 7 years ago
parent
commit
640b224525
  1. 21
      docs/modules/Traits.md
  2. 2
      src/trait_manager/view/TraitSelectView.js
  3. 5
      src/trait_manager/view/TraitView.js

21
docs/modules/Traits.md

@ -196,10 +196,29 @@ If you need to change some trait on your component you can update it wherever yo
The trait is a simple property of the component so to get the complete list of current traits you can use this:
```js
const traits = editor.getSelected().get('traits');
const component = editor.getSelected(); // Component selected in canvas
const traits = component.get('traits');
traits.forEach(trait => console.log(trait.props()))
```
In case you need a single one:
```js
const component = editor.getSelected();
console.log(component.getTrait('type').props()); // Finds by the `name` of the trait
```
If you want, for example, updating some property of the trait, do this:
```js
// Let's update `options` of our `type` trait, defined in Input component
const component = editor.getSelected();
component.getTrait('type').set('options', [
{ id: 'opt1', name: 'New option 1'},
{ id: 'opt2', name: 'New option 2'},
])
```
## Define new Trait type

2
src/trait_manager/view/TraitSelectView.js

@ -6,7 +6,7 @@ const $ = Backbone.$;
export default TraitView.extend({
init() {
this.listenTo(this.model, 'change:options', this.render);
this.listenTo(this.model, 'change:options', this.rerender);
},
templateInput() {

5
src/trait_manager/view/TraitView.js

@ -215,6 +215,11 @@ export default Backbone.View.extend({
return !this.model.get('noLabel');
},
rerender() {
this.model.el = null;
this.render();
},
render() {
const { $el, pfx, ppfx, model, target } = this;
const { type } = model.attributes;

Loading…
Cancel
Save