Asp.net Client Templates -
Is it possible to reuse a client template using asp.net ajax 4.0 client templates? I have a script as shown in the example below. I have two questions:
- I was unable to get the if condition in the client template
- How can I reuse the ul template tag for three types of Column data (col1, col2, col3 in json example)?
example code:
<style>
.sys-template { display:none; }
.list {width:220px; float:left; margin:0px 0px 0px 10px; background-color:#f2f2f2; }
</style>
<script src="MicrosoftAjax.debug.js" type="text/javascript"></script>
<script src="MicrosoftAjaxTemplates.debug.js" type="text/javascript"></script>
<script type="text/javascript">
var listItems = [{ item: "item1", col: "col1" },
{ item: "item2", col: "col1" },
{ item: "item3", col: "col1" },
{ item: "item4", col: "col2" },
{ item: "item5", col: "col2" },
{ item: "item6", col: "col2" },
{ item: "item7", col: "col2" },
{ item: "item8", col: "col3" },
{ item: "item9", col: "col3" },
{ item: "item10", col: "col3" }]
</script>
</head>
<body xmlns:sys="javascript:Sys" xmlns:dataview="javascript:Sys.UI.DataView" sys:activate="*">
<ul id="col1" class="list sys-template" sys:attach="dataview" dataview:data="{{ listItems }}">
<!--* if (col=="col1") { *-->
<li>{{item}}</li>
<!--* } *-->
</ul>
<ul id="col2" class="list sys-template" sys:attach="dataview" dataview:data="{{ listItems }}">
<!--* if (col=="col2") { *-->
<li>{{item}}</li>
<!--* } *-->
</ul>
<ul id="col3" class="list sys-template" sys:attach="dataview" dataview:data="{{ listItems }}">
<!--* if (col=="col3") { *-->
<li>{{item}}</li>
<!--* } *-->
</ul>
</body>
0
a source to share
2 answers
Something like this should work - I'm just typing this on the fly, so forgive me if it's not perfect.
<ul id="template1" class="sys-template">
<li code:if="col==$element.id">{{item}}</li>
</ul>
<ul id="col1" class="list sys-template" sys:attach="dataview" dataview:data="{{listItems }}" dataview:itemtemplate="template1">
</ul>
<ul id="col2" class="list sys-template" sys:attach="dataview" dataview:data="{{listItems }}" dataview:itemtemplate="template1">
</ul>
<ul id="col2" class="list sys-template" sys:attach="dataview" dataview:data="{{listItems }}" dataview:itemtemplate="template1">
</ul>
0
a source to share
In Preview 4, you enter code using the: before and code: after the attributes instead of the comment code blocks.
Template reuse is also possible. In fact, the framework will do this for you: if you specify a template property of two data views in one element, only one template will be compiled and used.
0