西纳特拉 +哈姆尔+ jQuery,从 javascript/jquery 渲染 haml
我正在开发一个使用 sinatra 和 haml 作为模板的项目。我希望能够使用 JQuery 附加一些 haml 部分。我希望将其添加到由类似事件触发的 js 函数中
....addEventListener(myWidget, 'click', function() {
$('targetDiv').append(RenderHamlTempalte('/my/file/location/');
});
,或者
....addEventListener(myWidget, 'click', function() {
$('targetDiv').append(RenderHamlTempalte('/my/file/location/', {options: here, options: here);
});
我已经在 github 上查看了一些相关项目,但确实找不到可以正确执行此操作的东西。
感谢您提供任何信息
更新:
这就是我最终的结果
var url = '/update&my&div/' + param;
$('.my-div').load(url);
,然后在我的 sinatra app.rb 中我可以返回我的 haml 部分
get ''/update&my&div/:params' do
# do some stuff
@make_variables_happen
haml :my_partial
end
I am working on a project using sinatra with haml for templates. I want to be able to append some of my haml partials using JQuery. I am hoping to add this to a js function being triggered by an event like so
....addEventListener(myWidget, 'click', function() {
$('targetDiv').append(RenderHamlTempalte('/my/file/location/');
});
or
....addEventListener(myWidget, 'click', function() {
$('targetDiv').append(RenderHamlTempalte('/my/file/location/', {options: here, options: here);
});
I have checked out a few related projects on github but really can't find something to do this with properly.
thanks for any info
UPDATE:
here was what I ended up going with
var url = '/update&my&div/' + param;
$('.my-div').load(url);
and then in my sinatra app.rb I can just return my haml partial
get ''/update&my&div/:params' do
# do some stuff
@make_variables_happen
haml :my_partial
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是使用如下工具: https://github.com/uglyog/clientside -haml-js
您必须将部分内容包装在
并将它们附加到您的 html 页面中的某个位置(我通常将它们添加到页面底部)。然后,您可以使用以下方式从 JavaScript 引用它们,
然后可以使用以下方式传递数据:
或根据您的示例:
One way to do this is to use a tool like: https://github.com/uglyog/clientside-haml-js
You would have to wrap your partials in
<script type="text/haml-template" id="template_id"> YOUR PARTIAL GOES HERE </script>
and append them somewhere in your html page (I usually add them at the bottom of the page). You can then reference them from JavaScript with:and then you can pass the data with:
or based on your example: