我已经看到很多关于如何将新TAB添加到fxml文件的现有选项卡窗格的答案。 我需要将内容添加到选项卡窗格的已经存在的选项卡中。 可能吗?如果是,我该怎么做?
答案 0 :(得分:0)
当然有可能。只需按照以下步骤操作:
IF(OBJECT_ID('YourTable','U') IS NOT NULL)
DROP TABLE YourTable
CREATE TABLE YourTable (Name VARCHAR(100), VALUE INT)
INSERT INTO YourTable VALUES
('A', 25),
('B', 30),
('A', 35),
('B', 40),
('A', 45)
DECLARE @Columns VARCHAR(1000), @ColumnAs VARCHAR(4000),@sql NVARCHAR(MAX)
SELECT @Columns = STUFF((SELECT ',' + '[' + CONVERT(VARCHAR(30), number, 121) + ']'
FROM master..spt_values N
WHERE n.number BETWEEN 1 AND (SELECT TOP 1 COUNT(*)
FROM YourTable
GROUP BY Name
ORDER BY COUNT(*) DESC)
AND TYPE = 'P'
FOR XML PATH('')), 1, 1, '')
SELECT @ColumnAs = REPLACE(@Columns,'],[','] as [Value],[') + 'as [Value]'
SET @sql = 'select [Name],' + @ColumnAs +'
from
(
select *,ROW_NUMBER() over(PARTITION by Name order by value) as [rn] from YourTable
) tab pivot
(
max([Value])
for rn in(' + @Columns +')
) as pvt'
EXEC SP_EXECUTESQL @sql
fx:id
绑定控制器中的Tab实例。setContent()
向其中添加内容。在FXML中
fx:id
在控制器中:
...
<Tab fx:id="myTab">
...