Closed marcinjackowiak closed 8 years ago
I overcome this situation using getter and setter:
bindings: {
'[name=price]': {
observe: 'price',
onGet: 'numToStr',
onSet: 'strToNum'
},
'[name=quantity]': {
observe: 'quantity',
onGet: 'numToStr',
onSet: 'strToNum'
}
}
//later:
strToNum: function (val) {
if (val != null) {
return +val;
}
},
numToStr: function (val) {
if (val != null) {
return val.toString();
}
}
Thanks, that did the trick. For anyone interested, I'm doing all the binding dynamically so this is the code i used:
view.addBinding(null, selector, {
observe: name,
onGet: function(val) {
if(val != null) {
return val.toString();
}
},
onSet: function(val) {
return +val;
}
});
I'm having an issue when i bind a select and retrieve a backbone model with value that is an integer.
The select is pre-populated:
The binding is added using addBinding method:
The json returned from the server is:
The select on the page does not reflect the correct schedule, it still shows Schedule 1 as selected.
The problem appears to be with the comparison on the following line (~line 569) since the data types are different:
I'm able to get it to work correctly after changing the line to use the less strict equality operator.
Is there a better way to handle this situation? I do not want to change the data type to string for the data coming from the server since integer is the correct data type reflecting the actual value.