How do I save and retrieving string arrays embedded as a property of the object
I'm working to model an object that has multiple embedded string arrays
App.Class = RL.Model.extend({
id: RL.attr('string'),
className: RL.attr('string'),
teachers: RL.hasMany('string'),
students: RL.hasMany('string')
});
It looks like everything is working, but when I display the Class object.
It looks like this:
This is a snippet of my template:
<h3 class="panel-title">Class Name: {{className}}</h3>
</div>
<div class="panel-body">
<ul class="list-group">
<li class="list-group-item">
<div class="row">
<div class="col-md-2">Teachers:</div>
<div class="col-md-10">{{teachers}}</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-2">Students:</div>
<div class="col-md-10">{{students}}</div>
</div>
</li>
Is there any special serialization/deserialization methods that I need implement in order to display it as a simple string both from the model and to the model when saving? And if so, where would those methods live?
Thanks
@reedyrm if you just make those properties string attributes ( teachers: RL.attr('string') ), it will turn the array data into a string of comma separated values.
Also, you can omit the id attribute in your model, as its automatically added.
Thanks for the quick response. That fixed my problem.