Ruby methods within Javascript within HAML

前端 未结 2 427
别跟我提以往
别跟我提以往 2020-12-23 17:30

I have a jQuery script that adds a new field to a form, and this field contains dynamic information from an array. The problem is that I can\'t figure out how to add an arra

2条回答
  •  孤城傲影
    2020-12-23 17:37

    Try this, it should work (all i did was remove a single space in the fifth line and add the closing quote on the sixth):

    %script(type="text/javascript")
      $('#mylink').click(function() {
      $('#mylink').after('');
      )};
    

    However, assuming you're running this with a ruby script or framework of sorts, why not just do it outside the template? That would probably be most appropriate. In rails/sinatra and other frameworks, you could use a helper method to do this. If you look at the haml reference, they actually discourage use of - to evaluate ruby.

提交回复
热议问题