Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 17:30:29 +01:00
bugfix
Dieser Commit ist enthalten in:
Ursprung
949b28cecb
Commit
3066c22367
1 geänderte Dateien mit 19 neuen und 16 gelöschten Zeilen
|
@ -3,27 +3,30 @@ import Category from 'discourse/models/category';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
const value = this.get('field.value');
|
const property = this.field.property || 'id';
|
||||||
|
const value = this.field.value;
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
const property = this.get('field.property') || 'id';
|
this.set('categories', [...value].reduce((result, v) => {
|
||||||
const categories = [...value].map(v => {
|
let val = property === 'id' ? Category.findById(v) : Category.findBySlug(v);
|
||||||
return property === 'id' ?
|
if (val) result.push(val);
|
||||||
Category.findById(v) :
|
return result;
|
||||||
Category.findBySlug(v);
|
}, []));
|
||||||
});
|
|
||||||
this.set('categories', categories);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@observes('categories')
|
@observes('categories')
|
||||||
setValue() {
|
setValue() {
|
||||||
const categories = this.get('categories');
|
const categories = (this.categories || []).filter(c => !!c);
|
||||||
if (categories.length) {
|
const property = this.field.property || 'id';
|
||||||
const property = this.get('field.property') || 'id';
|
|
||||||
let value = categories.length === 1 ?
|
if (categories.length) {
|
||||||
categories[0][property] :
|
this.set('field.value', categories.reduce((result, c) => {
|
||||||
categories.map(c => c[property]);
|
if (c && c[property]) {
|
||||||
this.set('field.value', value);
|
result.push(c[property])
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}, []));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
Laden …
In neuem Issue referenzieren