I have this code:
_.templateSettings = {interpolate : /\{\{(.+?)\}\}/g}; var _d = _.template($('#_d').html()); $.get('/foo', function(data) { $('#output').html(_d(data)); });
and in HTML:
<div id="_d"> {{name}} {{phone}} </div> <div id="output"></div>
/foo returns something like {"name":"joe","phone":"12345"} , but sometimes it does not have a phone , so it just returns {"name":"joe"} , which will delay the template’s evaluation, therefore, nothing will be printed in output . How to make a variable optional?
EDIT: /foo is out of my control
wiradikusuma
source share