I have a problem by rendering a script template .
model.example =self.template('template_example',model.example,'example');
Into template_example.html i have this script
<script>
var Example = (function() {
// Publics Method
function getValues() {
}
return {
getValues : getValues
};
}());
window.Example = Example
</script>
When loads the template into view ,i have error "Unexpected token function" .
If i have the same script into a file example.js and add <script type="text/javascript" src="js/example.js"></script> to template_example.html it works with no error.
Why?
Thanks
<script type="text/javascript" >
var a=1;
</script>
no works....
Script in console.log:
<script type="text/javascript" >\\nvar a=1;\\n\\n\\n</script>
<script type="text/javascript" >
var a=1;
</script>
<div class="widget wlightblue">
<div class="widget-content">
<div class="padd">
<div class="form-group">
<div class="alert alert-warning alert-dismissable"
style="display: none;" id="addTarifaArticuloMsg">
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
<div class="row">
<div class="col-lg-4">
<input class="form-control" placeholder="Codigo de Barras"
name="cbar">
</div>
<div class="col-lg-2">
<input class="form-control" placeholder="FMV" name="fmv">
</div>
<div class="col-lg-4">
<button type="button" class="btn btn-info"
onclick="javascript:tCbarras.Save()" name="savetarifa"
action="insert">Grabar</button>
<button type="button" class="btn btn-default"
onclick="tCbarras.SetValues()">Nueva</button>
</div>
</div>
</div>
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped tablesorter">
<thead>
<tr>
<th class="col-sm-6">CBAR<i class="fa fa-sort"></i></th>
<th class="col-sm-2"></th>
</tr>
</thead>
<tbody>
<!--
<tr>
<td class="col-sm-6">{cbar}</td>
<td class="action-table text-right">
<a onclick="tCbarras.Edit('{codex}')"><img src="css/img/table_edit.png" alt="editar"></a>
<a onclick="tCbarras.Delete('{codex}')"><img src="css/img/table_del.png" alt="delete""></a>
</td>
</tr>
-->
</tbody>
</table>
</div>
</div>
<a href="#addCbarras" class="btn" data-toggle="modal"> <i
class="fa fa-plus">Crear Nuevo Codigo de Barras</i>
</a>
</div>
</div>
But now if i send a null array of data [{}] , i have this error
Cannot call method 'toString' of undefined and no render the template.
Can i send a null array without this errors?
var arr = [{}];
if (Object.keys(arr[0]).length === 0)
arr = [];
This is example:
var model.data.cbar=[];
model.data.cbar = self.template('template_cbar', model.data.cbar,'cbarras');
self.template(template_name, model, [content_name_for_empty_model], [repository])
I need render always the template because the template has the button to add elements.
I send this array [{}] and add to template to control null values.
<!--
@{if model.cbar}
.....
@{endif}
-->
With this javascript :
<script type="text/javascript">
var a=1;
</script>
the chrome debugger send error in console "Unexpected token var" ,with the same script in example.js <script type="text/javascript" src="js/example.js"></script> it works.
the template in console.log() :
<script type="text/javascript">'+(String.fromCharCode(13)+String.fromCharCode(10))+' var a=1;'+(String.fromCharCode(13)+String.fromCharCode(10))+'</script>.....
Thanks Peter