Hi,
Recently our team started to pick up some knowledge in Hypermedia and Cj.
Sorry if the similar questions has been asked before in the group.
We have tried to use Cj in one of our Ajax call.
Now the problem we have is how to process Cj in front-end (we are using AngularJs for front-end application), we have different opinions among the team members.
Opinion 1:
Just access the data as an array, like below:
<tr>
<th>Current</th>
<th>Effective</th>
<th>{{ myCj.collection.items[0].data[2].name }}</th>
<th>By</th>
<th>Updated</th>
</tr>
</thead>
<tr data-ng-repeat="myData in myCj.collection.items">
<td><span ng-if="myData.data[0].value" class="glyphicon glyphicon-ok"></span></td>
<td>{{ myData.data[1].value }}</td>
<td>{{ myData.data[2].value }}</td>
<td>{{ myData.data[3].value }}</td>
<td>{{ myData.data[4].value }}</td>
</tr>
Pros:
- decoupling from the back-end. Whenever the data change, the code in the front-end won't break.
Cons:
- Not readable (suggestion for readability issue: wrap "myData.data[1].value" into a function, e.g. getCurrent(), "myData.data[2].value" to getEffective())
- Only useful if the usage of the data is just for "printing", but not when the front-end application need to process the actual data model.
Opinion 2:
Access the data like this:
<tr data-ng-repeat="item in collection.items()">
<td><span ng-if="item.get('current')" class="glyphicon glyphicon-ok"></span></td>
<td>{{ item.get('effective') }}</td>
<td>{{ item.get('label') }}</td>
<td>{{ item.get('by') }}</td>
<td>{{ item.get('updated') }}</td>
</tr>
or like this:
<tr data-ng-repeat="item in collection.items()">
<td><span ng-if="item.current" class="glyphicon glyphicon-ok"></span></td>
<td>{{ item.effective }}</td>
<td>{{ item.label }}</td>
<td>{{ item.by }}</td>
<td>{{ item.updated }}</td>
</tr>
Pros:
- The code is readable
- Object serialization.
Cons:
- Coupling with the backend, whenever the "name" of Cj's data changed, it will break.
Would appreciate if you guys can give us some advice/recommendation on processing/parsing the Cj in the front-end!
Thanks. :-)
Regards,
kkw