0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-26 11:00:28 +01:00
Dieser Commit ist enthalten in:
Angus McLeod 2020-04-15 13:21:40 +10:00
Ursprung 949b28cecb
Commit 3066c22367

Datei anzeigen

@ -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);
const property = this.field.property || 'id';
if (categories.length) { if (categories.length) {
const property = this.get('field.property') || 'id'; this.set('field.value', categories.reduce((result, c) => {
let value = categories.length === 1 ? if (c && c[property]) {
categories[0][property] : result.push(c[property])
categories.map(c => c[property]); }
this.set('field.value', value); return result;
}, []));
} }
} }
}); });