DataView: access #data# during item rendering in a Javascript function

Hi all,

I’m building a Dataview using one of the available provided samples. What I’d like to do is to have access to one of the variables of the data array passed to the DataView object.

I’m using this item template:

<div id="item_tpl" style="display:none">
  <div style='box-shadow:1px 1px 5px #444;'>
	<div style='padding:4px 20px; overflow: auto'>
		<div style="width:100%;">#file#</div>
		<div id=#file# style="width:40%; float: left; ">
			<script type="text/javascript">
				console.log("#"file#");
			</script>
			<li class='tag'>dummy</li>
		</div>
		<div style="width: 60%; float: right; " ><center><img src="img/3.png"/></center></div>
	</div>
  </div>
</div>

Note how the data in #file# is rendered in the <div>. This works like a charm. However, what I need too is such value within the <script> tag. Note the console.log entry: that is not working. I get a “#file#” text in the console log.

How can I do that?

Thanks

Hi,

In such a case you will need to use a function template:

view:"dataview", template:function(obj){
   console.log(obj.file);
   return "<div>"+obj.file+"</div>";
}

Yep, you can’t embed js blocks in the HTML template. Such blocks will be executed once, while initial page rendering and will not be reused in the component.

Tested and works like a charm. That solves my problem!! :))

Thanks a lot, Helga