21282 Posts in 5730 Topics by 2601 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 347 Views |
-
Child Control in Java Script ?

10 June 2012 at 2:18am
Hey,
I try to fill an array for a JS Timeline with Data from Silverstripe.I'm looking for something like:
<script type="text/javascript">
...
var event_data =
{
"dateTimeFormat": "ISO 8601",
"events":[
<% control children %>
{ "start": $StartDate,
"end": $EndDate,
"title": $Title,
"content": $Content },
<% end_control %>]
};
...
</script>Can anybody help? Is there a workaround?
Thanks
-
Re: Child Control in Java Script ?

13 June 2012 at 7:47pm
Try it this way:
<div id="mycontent-container" style="display: none">
<% control children %>
<div class="StartDate">$StartDate</div>
<div class="EndDate">$EndDate</div>
<div class="Title">$Title</div>
<div class="Content">$Content</div>
<% end_control %>
</div>And in your javascript (jQuery) you can catch the content out of your mycontent-container:
var StartDate = $('#mycontent-container .StartDate').text();
var EndDate = $('#mycontent-container .EndDate').text();
... -
Re: Child Control in Java Script ?

13 June 2012 at 8:51pm
Thanks Bereusei,
i tried this way, but it did not catch the content. It returns something like <object object>.Furthermore I tried:
...
getElementById("Startdate")..
<div id="Startdate">$Startdate</div>
but without success!
Any other idea?
Thanks
-
Re: Child Control in Java Script ?

6 July 2012 at 2:27am
Try to change the div into spans:
<div id="mycontent-container" style="display: none">
<% control children %>
<span class="StartDate">$StartDate</span>
<span class="EndDate">$EndDate</span>
<span class="Title">$Title</span>
<span class="Content">$Content</span>
<% end_control %>
</div>Perhaps the ".text()" doesn´t catch divs.
-
Re: Child Control in Java Script ?

6 July 2012 at 2:47am
Is the control returning more than one start date/end date?
If so you might need to do something along the lines of:
$('#mycontent-container .StartDate').each(function(){
alert($(this).text());
});Though obviously not just alerting the data ;)
| 347 Views | ||
|
Page:
1
|
Go to Top |



