jeudi 8 juin 2017

Decoding UTF-8 string in javascript

I am trying to encode strings with UTF-8 when they are saved into the database, when I read them out the database within ember I decode then with decodeURIComponent

However I would like if a topic has a space for example 'word word' for it to be decoded as word word

at the moment it decodes it like this 'word+word'

is there a way to fix this issue?

import Ember from "ember";

export default Ember.Helper.extend({

localeService: Ember.inject.service('locale'),

compute(params) {
    let localeCode = this.get('localeService.currentLocaleCode');
    params[0].forEach(function (singleTopic) {
        if (singleTopic.name.hasOwnProperty("values")) {
            singleTopic.name.values[localeCode] = decodeURIComponent(singleTopic.name.values[localeCode]);
        } else {
            singleTopic.name = decodeURIComponent(singleTopic.name);
        }
    });
    return params[0];
}

});




Aucun commentaire:

Enregistrer un commentaire