I\'m trying to figure out how to use one of my view elements inside of a controller...
I know, I know: \"Don\'t do that!\" (99% of the time this is
You should use a client-side template. You should never return mark-up from a web service or API, just data. Have your JavaScript take the data, and then format it how you wish.
For example:
function getItems() {
$.get('/some/url', function(response) {
if (response.data.length > 0) {
for (var i = 0; i < response.data.length; i++) {
var item = response.data[i];
$('.results').append('- ' + item.title + '
');
}
}
});
};
This is just an example written off the cuff. Obviously you’ll need to write your own implementation.