Jump to:

23355 Posts in 17734 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Child Control in Java Script ?

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

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

Page: 1
Go to End
Author Topic: 591 Views
  • Noki
    Avatar
    Community Member
    6 Posts

    Child Control in Java Script ? Link to this post

    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

  • Bereusei
    Avatar
    Community Member
    94 Posts

    Re: Child Control in Java Script ? Link to this post

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

  • Noki
    Avatar
    Community Member
    6 Posts

    Re: Child Control in Java Script ? Link to this post

    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

  • jimmybrion
    Avatar
    Community Member
    1 Post

    Re: Child Control in Java Script ? Link to this post

    Yes it is not working me to just checked

  • Bereusei
    Avatar
    Community Member
    94 Posts

    Re: Child Control in Java Script ? Link to this post

    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.

  • kinglozzer
    Avatar
    Community Member
    138 Posts

    Re: Child Control in Java Script ? Link to this post

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

    591 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.