vaadin-grid 相关问题


列的 maxWidth 无法使用 ag-grid 中的 autoAutoSize 函数调整大小

我正在尝试将 autosizecolumns 功能与 AG-Grid 和 Angular 框架一起应用。当函数执行时,列将默认采用内容的宽度。因此我为


React 中 Tailwind 动态类值编译的问题[重复]

我目前在尝试基于 Tailwind CSS 中动态生成的网格大小变量创建网格时遇到问题。当我使用变量设置 grid-template-rows 和 grid-template-co...


CSS Grid 使页面自动滚动

我一直在论坛上寻找解决这个问题的方法,我能找到的最接近的就是这个。但似乎没有解决办法。 我有一个 CSS 网格,它是 grid-template-columns: Repeat(auto-fill,...


在 Angular 15 升级中遇到加载器解析 ag-grid/angular.css 文件的问题

我在将 Angular 14 升级到 15 时遇到此构建错误。 我尝试添加 css 加载器,但没有用 ./node_modules/@ag-grid-community/styles/ag-grid.css?ngGlobalStyle:1:0 - 错误:模块解析失败...


在 MUI Data Grid v6 中更新另一个单元格时,如何在编辑模式下更新一个单元格?

我正在使用 MUI Data Grid v6 组件并利用其内置的 CRUD 编辑功能。我有多个列,所有列都可以编辑。在我的“类别&...”列中选择新值后


角度同步融合网格过滤

如何在 Syncfusion Grid 中过滤时禁用自动完成功能 我试过这个: 动作开始(参数){ if (args.requestType === '过滤' && args.currentFilterObject.value == null) { ...


将 4 个 div 级联排列为 4 列

我需要排列 4 个层叠的 div,看起来像是 4 列。 这是我的html结构(我无法修改它) 1111 我需要排列 4 个层叠的 div,看起来像是 4 列。 这是我的html结构(我无法修改它) <div class="col1"> 1111 <div class="col2"> 2222 <div class="col3"> 3333 <div class="col4"> 4444 </div> </div> </div> </div> 我需要它在使用时看起来像: display: grid; grid-template-columns: repeat(4, minmax(200px, 1fr)); 我也尝试过 grid-template-areas 但没有达到预期的结果。 好的,所以您需要容器是网格容器,然后元素都属于相同的子级别(即它们都需要属于相同的子元素)。因此你需要重构你的 html 来解决这个问题。这里有一个有用的链接,可以帮助您快速了解如何使用 css 网格。话虽如此,这里有一个 html/css 示例演示了您想要实现的目标。希望这可以帮助您有一个良好的开端。请注意,此示例使用您的值,并将强制每列至少为 200 像素(您显然可以根据您的用例进行更改)。 .grid-container{ display: grid; grid-template-columns: repeat(4, minmax(200px, 1fr)); } <div class="grid-container"> <div class="col1"> 1111 </div> <div class="col2"> 2222 </div> <div class="col3"> 3333 </div> <div class="col4"> 4444 </div> </div>


在 AgGrid 中显示组行的单元格值

我正在与 Ag-Grid 企业合作并使用 rowModelType 作为服务器端 我只想显示组行上第二列和第三列的一些自定义值(以红线标记)。 我有检查...


Selenium Grid 未检测到 Docker yaml 文件中的集成

我正在尝试为我的投资组合构建一个自动化测试项目。但我面临着同样的问题。我创建了一个 Docker YAML 文件来编写配置以在 chrome 和


MUI X DataGrid 在分页结果时仅显示一行

我正在使用 MUI X Data Grid v5 和 Tanstack React Query v4 我正在尝试在我的 Datagrid 组件上使用分页,当页面最初加载时,它会按预期正常获取并加载网格。


ALV GRID 不会根据值表检查输入,并且不显示匹配代码

我创建了一个包含 5 个字段的自定义表格: MANDT:数据元素 MANDT VBELN:数据元素 VBELN_VA POSNR:数据元素 POSNR_VA EXT_ID:自定义数据元素 VALUE:自定义数据元素 我已经定义了


为什么 Android 上两个组件之间的切换速度如此之慢?

我正在使用 Expo/React Native/Typescript 构建一个类似于填字游戏的小型拼图应用程序。 这是 PuzzleMain 组件的精简版本: const PuzzleMain:React.FC 我正在使用 Expo/React Native/Typescript 构建一个类似于填字游戏的小型拼图应用程序。 这是 PuzzleMain 组件的精简版本: const PuzzleMain: React.FC<PuzzleMainProps> = ({ navigation }) => { let puzzle: AcrosticPuzzleData = parseAcrosticPuzzle(PUZZLE_TEXT); const grid = <PuzzleGrid puzzle={puzzle} />; const clueView = <PuzzleCluesView puzzle={puzzle} />; const [index, setIndex] = React.useState(0); return <View style={styles.container}> {index == 0 ? grid : clueView} <View style={styles.keyboardContainer}> <Button onPress={() => setIndex(index == 1 ? 0 : 1)} title={"See " + routes[index == 0 ? "Grid" : "Clues"].key} /> <Keyboard /> </View> </View>; } 总结一下,有“网格”组件和“线索”组件,并通过按钮在它们之间进行切换。 毫不夸张地说,在我用来测试的 Pixel 5 上点击此按钮大约需要 3 秒的时间才能进行更改。我在这里做错了什么?使用Expo在网络上打开这个,它立即发生,所以可能它是Android特有的? 我尝试过的事情: 记住 PuzzleGrid 和 PuzzleCluesView 组件(const PuzzleGrid: React.FC<Props> = memo(({ puzzle }) ...。这基本上没有什么区别。我检查过,在我为备忘录功能制作的自定义拼图比较器中没有打印任何内容,所以我认为它没有重新渲染。 改用 TabView 在组件之间滑动 - 这有效!但说实话,我真的更喜欢两者兼得,而且当我将其合并到 TabView 实现中时,按钮同样很慢。 使用 npx expo start --no-dev 并仅构建一个 apk 并安装 - 这使得速度更快,但仍然可能需要整整一两秒,这太慢了。 正如我所看到的,您正在执行条件渲染,因此每次条件更改时,整个组件都会被创建为新组件。这种方法会使渲染速度变慢,具体取决于组件的重量。 为什么备忘录不起作用? Memo 是一种优化技术,并不能保证性能提升。 现在,提升加载速度 内部优化PuzzleGrid和PuzzleCluesView,比如每个可以接收重复道具的子组件都会被memo覆盖,重型物品会异步加载,使用loader。 使用 InteractionManager 提高加载速度,并帮助显示加载程序而不冻结 UI。 不要卸载组件,而是重叠它们并使用可见性,因为可见性不会卸载组件 而不仅仅是 {index == 0 ? grid : clueView}你可以尝试类似的事情 <View> {grid} <View style={{ // Add height and other required props to make it visible position: 'absolute', visibility: index == 0 ? 'hidden' : 'visible', }}> {clueView} </View> </View>


Pinia 对象在 Vue 中的 foreach 后失去反应性

我有这个嵌套的foreach BalanceItemList.vue ... 我有这个嵌套的 foreach BalanceItemList.vue <template> <div v-for="category in categoryItemsStore.balanceCategories" :key="category.id" class="mt-5"> <div class="border-black border-b bg-gray-200"> <span class="font-bold w-full">{{ category.name }}</span> </div> <div v-for="balanceItem in category.balance_items" :key="balanceItem.id"> {{ balanceItem.total = 500 }} <balance-item :balance-item="balanceItem" @update-balance-item="update"/> </div> <div> <balance-item-create :category="category.id" @create-balance-item="update"/> </div> <div v-if="categoryItemsStore.totals[category.id]" class="grid grid-cols-4-b t-2 ml-2"> <div :class="category.is_positive ? '': 'text-red-600' " class="col-start-4 border-t-2 border-black font-bold"> &euro;{{ categoryItemsStore.totals[category.id].total }} </div> </div> </div> </template> 我像这样检查了“balanceItem”的反应性 {{ balanceItem.total = 500 }} 它在商店中更新,但随后我有了我的平衡项目组件: BalanceItem.vue <script setup> import {reactive} from "vue"; import {useForm} from "@inertiajs/vue3"; import NumberInput from "@/Components/NumberInput.vue"; import {UseCategoryItemsStore} from "@/Stores/UseCategoryItemsStore.js"; const categoryItemStore = UseCategoryItemsStore() const props = defineProps({balanceItem: Object, errors: Object}) let item = reactive(props.balanceItem); const form = useForm(item); const emit = defineEmits(['update-balance-item']) const submit = () => { form.post(route('balance-item.update'), { preserveScroll: true, onSuccess: () => { props.balanceItem.total = 500 categoryItemStore.updateBalanceItemsTotals(form) emit('update-balance-item') } }) } </script> <template> <form @submit.prevent="submit"> <div class="grid grid-cols-4-b"> <span>{{ item.name }}</span> <NumberInput v-model="form.count" autofocus class=" mr-4 mt-1 block" type="number" @update:model-value="submit" /> <div :class="item.item_category.is_positive ? '' : 'text-red-600'" class="flex place-items-center"> <div class="pt-1 mr-1">&euro;</div> <NumberInput v-model="form.amount" :class="form.errors.amount ? 'border-red-600' : ''" autofocus class="mt-1 mr-4 w-5/6" type="text" @update:model-value="submit" /> </div> <div :class="item.item_category.is_positive ? '' : 'text-red-600'" class="flex place-items-center"> <div class="pt-1 mr-1 w-5/6">&euro;</div> <NumberInput v-model="form.total" autofocus class="mt-1 block" disabled style="max-width: 95%" type="text" /> </div> </div> </form> </template> 这是我测试反应性的商店。如果我增加输入的数字,则项目的计数保持不变 UseCategoryItemsStore.js import {defineStore} from "pinia"; import {ref} from "vue"; export const UseCategoryItemsStore = defineStore('UseCategoryItemsStore', () => { const balanceCategories = ref([]) const totals = ref([]) function getBalanceItems() { axios.get(route('balance-item.index')).then((response) => { balanceCategories.value = response.data // console.log(balanceCategories.value) }) } function getTotals() { axios.get(route('balance-item.totals')).then((response) => totals.value = response.data) } function getData() { getTotals() getBalanceItems() } function updateBalanceItemsTotals(selectedItem) { balanceCategories.value.forEach((category) => { category.balance_items.forEach((item) => { if (item.id === selectedItem.id) { // item.total = item.count * item.amount console.log(item) } }) }) } getTotals() getBalanceItems() return {balanceCategories, totals, getBalanceItems, getTotals, getData, updateBalanceItemsTotals} }) 在此测试中,我执行“props.balanceItem.total = 500”。但如果我检查商店,它不会更新。看来将“balanceItem”分配给一个道具会失去与我的 Pinia 商店的反应性。我可以使用“form.total = form.count * form.amount”手动更新我的表单,但这对我来说似乎很老套,我想使用 Pinia 商店的反应性。我考虑过根据“BalanceItem”获取 Pina 项目,但这似乎也很棘手。谁知道为什么失去反应性? 我有laravel 10.39、vue3.2.41和pinia 2.1.17惯性0.6.11。到目前为止我知道的所有最新版本。 我像这样更新我的表格和商店: <script setup> import {useForm} from "@inertiajs/vue3"; import NumberInput from "@/Components/NumberInput.vue"; import {UseCategoryItemsStore} from "@/Stores/UseCategoryItemsStore.js"; const categoryItemStore = UseCategoryItemsStore() const props = defineProps({balanceItem: Object, errors: Object}) let item = categoryItemStore.getItemById(props.balanceItem); let form = useForm(item); const emit = defineEmits(['update-balance-item']) const submit = () => { form.post(route('balance-item.update'), { preserveScroll: true, onSuccess: () => { item = categoryItemStore.updateItem(form) form = useForm(item) emit('update-balance-item') } }) } </script> 我将此功能添加到我的商店: import {defineStore} from "pinia"; import {ref} from "vue"; export const UseCategoryItemsStore = defineStore('UseCategoryItemsStore', () => { const balanceCategories = ref([]) const totals = ref([]) function getBalanceItems() { axios.get(route('balance-item.index')).then((response) => { balanceCategories.value = response.data // console.log(balanceCategories.value) }) } function getItemById(item) { let category = balanceCategories.value.find((category) => { return category.id === item.item_category_id }) return category.balance_items.find((item_from_store) => { return item_from_store.id === item.id }) } function updateItem(form) { const item = getItemById(form) item.count = form.count item.amount = form.amount item.total = item.count * item.amount return item } function getTotals() { axios.get(route('balance-item.totals')).then((response) => totals.value = response.data) } function getData() { getTotals() getBalanceItems() } getTotals() getBalanceItems() return {balanceCategories, totals, getBalanceItems, getTotals, getData, getItemById, updateItem} }) 假设如果帖子获得 200,我的表单值可用于更新商店和更新表单。这是我能想到的最好的


将值从用户控件传递到同一用户控件wpf c#中的另一个?

我有四个用户控件,我尝试将值从用户控件传递到另一个用户控件,这些用户控件存在于同一个用户控件中。 这个 xml 主页面 ` 我有四个用户控件,我尝试将值从用户控件传递到另一个用户控件,这些用户控件存在于同一个用户控件中。 这个 xml 主页面 ` <Grid> <StackPanel Background="#FFF"> <local:mwidget x:Name="mwidget" Loaded="UserControl1_Loaded"/> <local:addemploy x:Name="addemploy" Visibility="Hidden"/> <local:editemploy x:Name="editemploy" Visibility="Hidden" /> </StackPanel> </Grid>` 还有这个代码 ` private void UserControl1_Loaded(object sender, RoutedEventArgs e) { mwidget.ShowUserControl2Requested += OnShowUserControl2Requested; addemploy.ShowUserControl1Requested += OnShowUserControl1Requested; editemploy.ShowUserControl1Requestedd += ShowUserControl1Requestedd; mwidget.ShowUserControl2Requestedd += ShowUserControl1Requesteddd; } private void OnShowUserControl2Requested(object sender, EventArgs e) { addemploy.Visibility = Visibility.Visible; mwidget.Visibility = Visibility.Collapsed; } private void OnShowUserControl1Requested(object sender, EventArgs e) { mwidget.Visibility = Visibility.Visible; addemploy.Visibility = Visibility.Collapsed; } private void ShowUserControl1Requestedd(object sender, EventArgs e) { mwidget.Visibility = Visibility.Visible; editemploy.Visibility = Visibility.Collapsed; } private void ShowUserControl1Requesteddd(object sender, EventArgs e) { editemploy.Visibility = Visibility.Visible; mwidget.Visibility = Visibility.Collapsed; }` 这个代码mwidget ` public partial class mwidget : UserControl { public event EventHandler ShowUserControl2Requested; public event EventHandler ShowUserControl2Requestedd; public mwidget() { InitializeComponent(); } private void add_employ(object sender, RoutedEventArgs e) { ShowUserControl2Requested?.Invoke(this, EventArgs.Empty); } private void edit_employ(object sender, System.Windows.RoutedEventArgs e) { ShowUserControl2Requestedd?.Invoke(this, EventArgs.Empty); } }` 所以我想将值从 mwidget 传递到 editemploy,我尝试了一些解决方案,但不起作用 您需要在 mwidget 和 editemploy 中创建 DependencyPropertys 并将它们相互绑定。 (注意:在下面的示例中,我使用了 OneWayToSource。这可以防止 editemploy 更改 mwidget 中的值。如果您不想这样做,请将其更改为 TwoWay。) m小部件: public static readonly DependencyProperty MyValueProperty = DependencyProperty.Register( nameof(MyValue), typeof(bool), typeof(mwidget)); public bool MyValue { get => (bool)GetValue(MyValueProperty); set => SetValue(MyValueProperty, value); } 编辑雇佣: public static readonly DependencyProperty MyPassedValueProperty = DependencyProperty.Register( nameof(MyPassedValue), typeof(bool), typeof(editemploy)); public bool MyPassedValue { get => (bool)GetValue(MyPassedValueProperty); set => SetValue(MyPassedValueProperty, value); } xaml: <local:mwidget x:Name="mwidget" Loaded="UserControl1_Loaded"/> <local:addemploy x:Name="addemploy" Visibility="Hidden"/> <local:editemploy x:Name="editemploy" Visibility="Hidden" MyPassedValue="{Binding ElementName=mwidget, Path=MyValue, Mode=OneWayToSource}" />


.NET MAUI:自定义Shell TitleView并绑定到当前页面标题

我想用我自己的自定义布局替换默认的 Shell 标头,如下所示: 我想用我自己的自定义布局替换默认的 Shell 标头,如下所示: <?xml version="1.0" encoding="UTF-8" ?> <Shell x:Class="MyNamespace.App.AppShell" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:MyNamespace.App" xmlns:pages="clr-namespace:MyNamespace.App.Pages" BindingContext="{x:Static local:MainView.Instance}" Shell.FlyoutBehavior="{Binding ShellFlyoutType}" x:Name="shellMain"> <Shell.TitleView> <Grid ColumnDefinitions="*,200"> <Label BindingContext="{x:Reference shellMain}" Text="{Binding Path=CurrentPage.Title, Mode=OneWay}" FontSize="Large" TextColor="White" /> <ActivityIndicator IsRunning="{Binding IsBusy}" Color="Orange" Grid.Column="1" HorizontalOptions="End" /> </Grid> </Shell.TitleView> <ShellContent Title=" Login" ContentTemplate="{DataTemplate local:MainPage}" Route="login" FlyoutItemIsVisible="False" /> <ShellContent Title="Dashboard" ContentTemplate="{DataTemplate pages:DashboardPage}" Route="dashboard" /> </Shell> 我无法绑定当前页面标题。 我的 AppShell.xaml Shell 声明如下 <Shell ... x:Name="shellMain"> 作为替代方案,您可以在 OnNaviged 方法中设置 titleview : 在 AppShell.xaml 中,定义标签的名称 <Shell.TitleView> <Grid ColumnDefinitions="*,200"> <Label BindingContext="{x:Reference shellMain}" x:Name="mylabel" FontSize="Large" TextColor="White" /> <ActivityIndicator IsRunning="{Binding IsBusy}" Color="Orange" Grid.Column="1" HorizontalOptions="End" /> </Grid> </Shell.TitleView> 在AppShell.xaml.cs中,重写OnNaviged方法,获取当前项目 protected override void OnNavigated(ShellNavigatedEventArgs args) { base.OnNavigated(args); var shellItem = Shell.Current?.CurrentItem; string title = shellItem?.Title; int iterationCount = 0; while (shellItem != null && title == null) { title = shellItem.Title; shellItem = shellItem.CurrentItem; if (iterationCount > 10) break; // max nesting reached iterationCount++; } myLabel.Text = title; } 希望它对你有用。 我正在尝试同样的方法来修改 TitleView 的外观。它可以在 iOS 上运行,尽管那里还有另一个错误。但在 Android 上我遇到了同样的问题。在前进导航中,它会更新标题,但当您按后退按钮时,标题不会更新。我已经打开了一个问题并添加了一个存储库。 https://github.com/dotnet/maui/issues/12416#issuecomment-1372627514 还有其他方法可以修改TitleView的外观吗? 我使用视图模型开发了这个解决方法,主要不是为了提供 MVVM 解决方案,而是因为其他建议的答案对我不起作用。 (我怀疑 Liqun Shen 2 月 15 日针对他自己的问题的评论中的建议会起作用。但我没有注意到这一点,直到我自己修复)。 当前页面的标题保存在可由 shell 的视图模型和每个内容页面的视图模型访问的类中: public class ServiceHelper { private static ServiceHelper? _default; public static ServiceHelper Default => _default ??= new ServiceHelper(); internal string CurrentPageTitle { get; set; } = string.Empty; } shell 中每个内容页面的视图模型提供其页面标题。为了促进这一点,大部分工作都是由基本视图模型完成的,它们都是从该模型派生而来的: public abstract class ViewModelBase(string title) : ObservableObject { private ServiceHelper? _serviceHelper; public string Title { get; } = title; internal ServiceHelper ServiceHelper { get => _serviceHelper ??= ServiceHelper.Default; set => _serviceHelper = value; // For unit testing. } public virtual void OnAppearing() { ServiceHelper.CurrentPageTitle = Title; } } 每个 shell 内容页面视图模型只需要让其基础视图模型知道它的标题: public class LocationsViewModel : ViewModelBase { public LocationsViewModel() : base("Locations") { } } 每个 shell 内容页面都需要在其视图模型中触发所需的事件响应方法: public partial class LocationsPage : ContentPage { private LocationsViewModel? _viewModel; public LocationsPage() { InitializeComponent(); } private LocationsViewModel ViewModel => _viewModel ??= (LocationsViewModel)BindingContext; protected override void OnAppearing() { base.OnAppearing(); ViewModel.OnAppearing(); } } Shell 的视图模型为标题栏提供当前页面的标题: public class AppShellViewModel() : ViewModelBase(Global.ApplicationTitle) { private string _currentPageTitle = string.Empty; public string CurrentPageTitle { get => _currentPageTitle; set { _currentPageTitle = value; OnPropertyChanged(); } } public void OnNavigated() { CurrentPageTitle = ServiceHelper.CurrentPageTitle; } } Shell 需要在其视图模型中触发所需的事件响应方法: public partial class AppShell : Shell { private AppShellViewModel? _viewModel; public AppShell() { InitializeComponent(); } private AppShellViewModel ViewModel => _viewModel ??= (AppShellViewModel)BindingContext; protected override void OnNavigated(ShellNavigatedEventArgs args) { base.OnNavigated(args); ViewModel.OnNavigated(); } } 最后,Shell 的 XAML 在标题栏/导航栏上显示由 Shell 视图模型提供的当前页面的标题: <Shell.TitleView> <HorizontalStackLayout VerticalOptions="Fill"> <Image Source="falcon_svg_repo_com.png" HeightRequest="50"/> <Label x:Name="CurrentPageTitleLabel" Text="{Binding CurrentPageTitle}" FontSize="24" Margin="10,0" VerticalTextAlignment="Center"/> </HorizontalStackLayout> </Shell.TitleView>


如何使用 Tailwind CSS 实用程序类使部分粘性

在我的 Next.js Web 应用程序中,我有一个页面,如下所示: 我想让该部分(用 标签包裹)以蓝色粘性突出显示,这样当我滚动时,它会保持在原来的位置,并且只有 m... 在我的 Next.js Web 应用程序中,我有一个页面,如下所示: 我想使该部分(包含在 <aside> 标签中)以蓝色粘性突出显示,这样当我滚动时,它会保持在原来的位置,并且只有主要部分(包含图表的部分)会滚动。 这是 layout.tsx 文件: import { dashboardConfig } from "@/config/dashboard"; import { MainNav } from "@/components/nav/main-nav"; import { DashboardNav } from "@/components/nav/dashboard-nav"; interface DashboardLayoutProps { children?: React.ReactNode; } export default async function DashboardLayout({ children, }: DashboardLayoutProps) { return ( <div className="flex min-h-dvh flex-col relative"> <header className="container z-40 bg-background"> <MainNav /> </header> <div className="container grid flex-1 gap-12 md:grid-cols-[200px_1fr] mt-32 mb-12 relative"> <aside className="hidden w-[200px] flex-col md:flex sticky top-0"> <DashboardNav items={dashboardConfig.sidebarNav} /> </aside> <main className="flex w-full flex-1 flex-col overflow-hidden"> {children} </main> </div> </div> ); } 请注意,我已将类 sticky 和 top-0 应用于我想要粘贴位置的部分。但它不起作用。 我做错了什么? 考虑通过 align-self: start 将 self-start 应用到粘性元素。默认情况下,它将具有 align-self: stretch,这将使其成为其父网格元素的完整高度,因此不会观察到粘性效果。通过应用 align-self: start,它的高度将仅与其内容一样高,如果存在垂直自由空间,则可以观察到粘性效果。 const dashboardConfig = { sidebarNav: '' }; const MainNav = () => 'MainNav'; const DashboardNav = () => 'DashboardNav'; function DashboardLayout({ children, }) { return ( <div className="flex min-h-dvh flex-col relative"> <header className="container z-40 bg-background"> <MainNav /> </header> <div className="container grid flex-1 gap-12 md:grid-cols-[200px_1fr] mt-32 mb-12 relative"> <aside className="hidden w-[200px] flex-col md:flex sticky top-0 self-start"> <DashboardNav items={dashboardConfig.sidebarNav} /> </aside> <main className="flex w-full flex-1 flex-col overflow-hidden"> {children} </main> </div> </div> ); } function App() { return ( <DashboardLayout> <div class="h-[200vh]"></div> </DashboardLayout> ); } ReactDOM.createRoot(document.getElementById('app')).render(<App/>); <script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js" integrity="sha512-8Q6Y9XnTbOE+JNvjBQwJ2H8S+UV4uA6hiRykhdtIyDYZ2TprdNmWOUaKdGzOhyr4dCyk287OejbPvwl7lrfqrQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js" integrity="sha512-MOCpqoRoisCTwJ8vQQiciZv0qcpROCidek3GTFS6KTk2+y7munJIlKCVkFCYY+p3ErYFXCjmFjnfTTRSC1OHWQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <script src="https://cdn.tailwindcss.com/3.4.1"></script> <div id="app"></div>


如何将 Div 布局转换为基于 CSS 样式的 HTML 表格?

我正在开发一个项目,需要使用 、、、 和 将使用 元素设计的复杂布局转换为 HTML 表格 我正在开发一个项目,需要将使用 <div> 元素设计的复杂布局转换为使用 <table>、<tr>、<td>、<colspan> 和 <rowspan> 标签的 HTML 表格。布局当前使用 CSS 进行样式设置,我希望在将其转换为表格格式时保留相同的结构和外观。 输入: 我有一系列 <div> 元素,以表格格式表示标题和数据单元格。每个 <div> 都有多个类属性,对应于定义其位置和大小的特定 CSS 样式。这是当前基于 div 的布局的片段: <div class="c x1b y41 wf h14">Project</div> <div class="c x20 y43 w10 h6">2023</div> <div class="c x21 y43 w11 h6">2022</div> <div class="c x23 y43 w12 h6">2021</div> <div class="c x1e y43 w13 h6">2020</div> <div class="c x20 y41 w14 h9">Amount</div> <div class="c x26 y41 w15 h9">Ratio</div> <div class="c x21 y41 w16 h9">Amount</div> <div class="c x28 y41 w17 h9">Ratio</div> <div class="c x23 y41 w18 h9">Amount</div> <div class="c x29 y41 w19 h9">Ratio</div> <div class="c x1e y41 w1a h9">Amount</div> <div class="c x2a y41 w1b h9">Ratio</div> <div class="c x1b y44 wf h6">Income</div> <div class="c x20 y44 w14 h6">9.6</div> <div class="c x26 y44 w15 h6">100.00</div> <div class="c x21 y44 w16 h6">377.78</div> <div class="c x28 y44 w17 h6">100.00</div> <div class="c x23 y44 w18 h6">293.47</div> <div class="c x29 y44 w19 h6">100.00</div> <div class="c x1e y44 w1a h6">210.66</div> <div class="c x2a y44 w1b h6">100.00</div> CSS 样式: 布局由这些 CSS 样式控制,它们规定了 div 的尺寸和位置: .h14 {height: 41.215200px;} .h6 {height: 20.280000px;} .h9 {height: 20.311200px;} .w10 {width: 116.095200px;} .w11 {width: 116.251200px;} .w12 {width: 116.376000px;} .w13 {width: 122.959200px;} .w14 {width: 55.099200px;} .w15 {width: 60.216000px;} .w16 {width: 58.188000px;} .w17 {width: 57.283200px;} .w18 {width: 61.152000px;} .w19 {width: 54.600000px;} .w1a {width: 61.963200px;} .w1b {width: 60.372000px;} .wf {width: 73.008000px;} .x1b {left: 112.450000px;} .x1e {left: 537.830800px;} .x20 {left: 186.914000px;} .x21 {left: 303.641000px;} .x23 {left: 420.511000px;} .x26 {left: 242.801000px;} .x28 {left: 362.609000px;} .x29 {left: 482.287000px;} .x2a {left: 600.262000px;} .y41 {bottom: 490.373000px;} .y43 {bottom: 511.303000px;} .y44 {bottom: 469.313000px;} 预期结果: 我想将此布局转换为 HTML 表格。预期的表结构应类似于以下内容: <table border="1"> <tr> <td rowspan="2">Project</td> <td colspan="2">2023</td> <td colspan="2">2022</td> <td colspan="2">2021</td> <td colspan="2">2020</td> </tr> <tr> <td>Amount</td> <td>Ratio</td> <td>Amount</td> <td>Ratio</td> <td>Amount</td> <td>Ratio</td> <td>Amount</td> <td>Ratio</td> </tr> <tr> <td>Income</td> <td>9.6</div></td> <td>100.00</td> <td>377.78</td> <td>100.00</td> <td>293.47</td> <td>100.00</td> <td>210.66</td> <td>100.00</td> </tr> </table> 尝试: 我尝试了多种方法来解析 div 并应用它们的样式来创建表格,但没有一种方法有效。我已经尝试使用 JavaScript 动态读取 CSS 属性并将它们作为属性应用到表格单元格,但我在维护布局完整性方面遇到了问题,尤其是在跨越行和列时。 问题: 任何人都可以提供有关如何考虑 CSS 样式以编程方式将这种基于 div 的布局转换为 HTML 表格的指导或解决方案吗?如果您能帮助解析 CSS 以定义表中适当的 <colspan> 和 <rowspan> 值,我们将不胜感激。 如果您只想让它看起来像表格而不是语义。您可以尝试使用网格和固定数量的列来执行此操作,例如使用grid-template-columns: repeat(10, 1fr)。


© www.soinside.com 2019 - 2024. All rights reserved.