如何在Handlebars上生成元素执行JQuery函数?

时间:2014-10-06 12:09:52

标签: javascript jquery jquery-ui ember.js

我正在开发一个Ember应用程序,其中包括正常的把手 {{if}} 功能

我正在尝试从jqueryUI --- http://jqueryui.com/accordion/

实现accordion函数
{{if showContent}}  
 <div id="accordion">
      <h3>Section 1</h3>
      <div>
        <p>
        Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
        ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
        amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
        odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
        </p>
      </div>
      <h3>Section 2</h3>
      <div>
        <p>
        Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet
        purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor
        velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In
        suscipit faucibus urna.
        </p>
      </div>
      <h3>Section 3</h3>
      <div>
        <p>
        Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.
        Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero
        ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis
        lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui.
        </p>
        <ul>
          <li>List item one</li>
          <li>List item two</li>
          <li>List item three</li>
        </ul>
      </div>
    </div>

{{/if}}

脚本功能

  <script>
  $(function() {
    $( "#accordion" ).accordion();
  });
  </script>

没有被执行,因为我在 {{if}} 帮助器中附上 div id&#34; accordion&#34; 如何执行脚本之后div&#34;手风琴&#34;已加载到DOM

更新:我实际需要的一个JSBIN http://jsbin.com/wejaba/5/edit

1 个答案:

答案 0 :(得分:0)

showAccordion:function()
      {
        this.toggleProperty('showAcc');
        Ember.run.next(function() {
        $("#accordion" ).accordion();
         });
      }

我在ember run下运行手风琴脚本循环一切正常

http://jsbin.com/bogegizozeca/3/edit