Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Child Control in Java Script ?


Go to End


6 Posts   1514 Views

Avatar
Noki

Community Member, 6 Posts

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

Avatar
Bereusei

Community Member, 96 Posts

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();
...

Avatar
Noki

Community Member, 6 Posts

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

Avatar
jimmybrion

Community Member, 1 Post

14 June 2012 at 8:59pm

Yes it is not working me to just checked

Avatar
Bereusei

Community Member, 96 Posts

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.

Avatar
kinglozzer

Community Member, 187 Posts

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