Problem with script into template

36 views
Skip to first unread message

acam...@prosystem.es

unread,
Apr 17, 2014, 6:08:54 AM4/17/14
to tot...@googlegroups.com
Hi Peter,

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

acam...@prosystem.es

unread,
Apr 17, 2014, 6:22:36 AM4/17/14
to tot...@googlegroups.com, acam...@prosystem.es
With simple script

<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>

Peter Širka

unread,
Apr 17, 2014, 6:56:24 AM4/17/14
to tot...@googlegroups.com, acam...@prosystem.es
Hello,
please write me whole template declaration and total.js version.

Thanks :)

acam...@prosystem.es

unread,
Apr 17, 2014, 8:00:47 AM4/17/14
to tot...@googlegroups.com, acam...@prosystem.es
My Total.js version 1.3.1 and this is the template

<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">&times;</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>

Peter Širka

unread,
Apr 17, 2014, 8:06:00 AM4/17/14
to tot...@googlegroups.com, acam...@prosystem.es
Try to use new template syntax:

old: {property}
new: @{model.property}

New Template syntax is same as View syntax. Give me a feedback.

acam...@prosystem.es

unread,
Apr 17, 2014, 8:23:54 AM4/17/14
to tot...@googlegroups.com, acam...@prosystem.es
Ok,it works!!!

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?

Peter Širka

unread,
Apr 17, 2014, 8:40:58 AM4/17/14
to tot...@googlegroups.com, acam...@prosystem.es
Yes .. because this property doesn't exist.
Problem is: [{}] - you must prepare an empty array [] - and this works.

Simple test:

var arr = [{}];

if (Object.keys(arr[0]).length === 0)
    arr
= [];

acam...@prosystem.es

unread,
Apr 17, 2014, 8:45:58 AM4/17/14
to tot...@googlegroups.com, acam...@prosystem.es
If i send an empty array [] i have error in self.template ,Content "cbarras" not found...


This is example:

var model.data.cbar=[];

model.data.cbar = self.template('template_cbar', model.data.cbar,'cbarras');

Peter Širka

unread,
Apr 17, 2014, 11:20:13 AM4/17/14
to tot...@googlegroups.com, acam...@prosystem.es
You have bad implementation:

self.template(template_name, model, [content_name_for_empty_model], [repository])

What is "cbarras"?
Thanks :-)

acam...@prosystem.es

unread,
Apr 17, 2014, 12:51:45 PM4/17/14
to tot...@googlegroups.com, acam...@prosystem.es
I corrected my implementation ,but the problem with javascript inline persists...

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

Peter Širka

unread,
Apr 19, 2014, 12:42:20 PM4/19/14
to tot...@googlegroups.com, acam...@prosystem.es
Can you send me example on my e-mail (petersirka(at)gmail(dot)com) with this problem?
Thanks.
Reply all
Reply to author
Forward
0 new messages