rails slim template: Uncaught SyntaxError: Unexpected token if
rails slim template: Uncaught SyntaxError: Unexpected token if
我有一个苗条的模板previews.slim
= render 'previews/demo_areas/skinny_demo_area', p_unit: @p_unit, size: 2
我在该文件上添加了 javascript:
javascript:
var rotationIndex = 0;
var auto_rotate = #{@p_unit.auto_rotate_highlight};
- if auto_rotate
rotateTextOverAds();
function rotateTextOverAds() {
var size_300x250_ads = $('.carousel_ad_unit.size_9700x250 .ad .ad-details');
$('.carousel_ad_unit.size_9700x250 .ad').each(function () {
$(this).find('.ad-details').hide();
});
rotationIndex += 1;
if rotationIndex > size_300x250_ads.length
rotationIndex = 1;
size_300x250_ads[rotationIndex - 1].style.display = 'block';
setTimeout(rotateTextOverAds, 2000)
}
基于rails实例变量@p_unit.auto_rotate_highlight
属性,我想运行一个函数。但是当我加载页面时,我的浏览器一直显示:
Uncaught SyntaxError: Unexpected token if
我该如何解决这个问题?
您正在混合 javascript 语法和 ruby(slim) 语法,在 javascript if 条件看起来像:
if (condition) {
// some code here
}
我有一个苗条的模板previews.slim
= render 'previews/demo_areas/skinny_demo_area', p_unit: @p_unit, size: 2
我在该文件上添加了 javascript:
javascript:
var rotationIndex = 0;
var auto_rotate = #{@p_unit.auto_rotate_highlight};
- if auto_rotate
rotateTextOverAds();
function rotateTextOverAds() {
var size_300x250_ads = $('.carousel_ad_unit.size_9700x250 .ad .ad-details');
$('.carousel_ad_unit.size_9700x250 .ad').each(function () {
$(this).find('.ad-details').hide();
});
rotationIndex += 1;
if rotationIndex > size_300x250_ads.length
rotationIndex = 1;
size_300x250_ads[rotationIndex - 1].style.display = 'block';
setTimeout(rotateTextOverAds, 2000)
}
基于rails实例变量@p_unit.auto_rotate_highlight
属性,我想运行一个函数。但是当我加载页面时,我的浏览器一直显示:
Uncaught SyntaxError: Unexpected token if
我该如何解决这个问题?
您正在混合 javascript 语法和 ruby(slim) 语法,在 javascript if 条件看起来像:
if (condition) {
// some code here
}