我正在使用Rails 4.2.3。我有以下Javascript文件夹
app/assets/javascripts/flot/
我希望此文件夹中的所有文件只包含在一个页面上(即只有一个来自控制器的动作)。是否可以在我的视图中对javascript_include_tag中的每个文件进行硬编码时执行此操作?注意,我对所有JS文件都包含在控制器的每个操作中的答案都不感兴趣。我只需要这些文件用于一个动作呈现的视图。
答案 0 :(得分:0)
您可以在该文件夹中创建一个主JS文件并输入
列表//= require [file name]
进入混音,然后从该列表加载所有这些。
然后在要使用的视图中包含以下行。
<%= javascript_include_tag "flot/[master file name]" %>
例如,您可以将文件命名为app/assets/javascripts/flot/main.js
然后内容将是
#flot/main.js
//= require_tree .
和
#your view
...
<%= javascript_include_tag "flot/main" %>
...
然后,添加到您的flot文件夹或子文件夹的任何文件都会自动添加到您的树中。只需确保您已flot
require_tree
application.js
Point location = new Point(0, 0);
ColorConverter cc = new ColorConverter();
foreach (var item in temp)
{
Panel pan = new Panel();
pan.AutoSize = false;
pan.Width = this.Width-75;
pan.Location = location;
pan.BackColor = (Color)cc.ConvertFromString("#" + item.Item3);
Label lbl = new Label();
lbl.Font = new Font("Arial", 12);
lbl.ForeColor = Color.White;
lbl.Text = item.Item2;
lbl.AutoSize = true;
lbl.MaximumSize = new Size(pan.Width - 5, 0);
lbl.Width = pan.Width - 10;
lbl.Location = new Point(lbl.Location.X + 5, lbl.Location.Y + 5);
//pan.Height = lbl.Height + 5;
pan.Controls.Add(lbl);
flowLayoutPanel1.Controls.Add(pan);
location = new Point(location.X - pan.Height, location.Y);
}
文件夹中pan.Height = lbl.Height + 5;
排除了DECLARE @cnt INT = 0
DECLARE @SQLQuery AS NVARCHAR(max)
DECLARE @items AS VARCHAR(500)
DECLARE @stline AS VARCHAR(500)
set @SQLQuery =''
while @cnt < 101
begin
set @items = 'LG_0' + convert(nvarchar(3),@cnt) + '_ITEMS'
set @stline = 'LG_0' + convert(nvarchar(3),@cnt) + '_01_STLINE'
if (OBJECT_ID (@items) is not null and OBJECT_ID(@stline) is not null )
set @SQLQuery = @SQLQuery + 'SELECT
ITM1.CODE, itm1.NAME, max (stl.date_) [latest date] , price as [latest price], '+ convert(nvarchar(3),@cnt) + ' as [proje kodu]
FROM ' + @items + ' ITM1 INNER JOIN ' + @stline + ' STL
ON ITM1.LOGICALREF = STL.STOCKREF
WHERE PRICE > 0
AND TRCODE = 1
AND CANCELLED = 0
AND INVOICEREF > 0
GROUP BY code, name, stl.DATE_ , price
UNION ALL
'
set @cnt = @cnt +1
end
-- SUBSTRING to remove last UNION ALL
--PRINT len(@SQLQuery)
set @SQLQuery = left ( @SQLQuery , len(@SQLQuery)-18)
--PRINT len(@SQLQuery)
-- print @SQLQuery
-- For debugging purposes
-- PRINT @SQLQuery
exec (@SQLQuery)
文件夹,如this link