fixstring Class
Custom string field transform that uses the fix-special-char
utility function to clean up malformed text sent
from the server. This allows string fields to be correctly and transparently used in templates without manually fixing
these characters for display on each use.
This transform is used when fixstring
is passed as the type parameter to the DS.attr function.
import DS from 'ember-data';
export default DS.Model.extend({
astring: DS.attr('fixstring'),
});
Item Index
Methods
Methods
deserialize
(
-
serialized
-
options
When given a serialize value from a JSON object this method must
return the deserialized value for the record attribute.
Example
`
javascript
deserialize: function(serialized, options) {
return empty(serialized) ? null : Number(serialized);
}
`
Returns:
The deserialized value
fixSpecialChar
(
String | Null
-
inputString
This function is useful for fixing a bad API behavior. In certain cases the server will insert HTML escape
sequences into text, and this will replace
&
sequences with &
, <
with <
and >
with >
.
Template helper and ember-data field versions of this function are available.
Parameters:
-
inputString
StringA string value to be transformed
Returns:
String | Null:
serialize
(
-
deserialized
-
options
When given a deserialized value from a record attribute this
method must return the serialized value.
Example
`
javascript
serialize: function(deserialized, options) {
return Ember.isEmpty(deserialized) ? null : Number(deserialized);
}
`
Parameters:
Returns:
The serialized value