Mvc嵌套类别表列表 [英] Mvc nested category table list

查看:63
本文介绍了Mvc嵌套类别表列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

How can I make recursive categories, like this:

computer <br />
computer > Lenovobr 
computer > Lenovo > p250
Electronic 
Electronic > Lise

how can I remove it in a spreadsheet?

What I have tried:

<pre>MVC nested category table list

推荐答案

最好的方法是在类别上使用父子关系,S / O有一个有效的解决方案:

c# - ASP.Net MVC:如何显示嵌套父级 - 使用递归技术的子关系 [ ^ ]



根据我的经验,如果你有很多类别和深度体验绩效问题;你可能想要缓存/持久化生成的层次结构。



已添加:将结构移动到数据库

下面是一个非常简单的DB表,用于保存此信息。您可能希望为这些添加描述性信息。有些人还会告诉你在带有约束的ParentID上添加外键...通常这不会有助于数据库本身的性能,但如果你使用的是ORM,例如Entity Framework,它可能会帮助你的应用程序更好了解你的数据库结构。
Best way to do this is to utilize a parent-child relationship on the categories, S/O has a valid solution:
c# - ASP.Net MVC: How to show nested parent-child relation using recursive technique[^]

From my experiences, if you have a lot of categories and depth experience performance issues; you may want to cache/persist the generated hierarchy.

Added: Moving the structure to the database
A very simple DB table for holding this information follows. You will probably want to add in descriptive information for these. Some people will also tell you to add in a Foreign Key on the ParentID with constraints... Generally this will not aid in performance within the DB itself, but if you are using an ORM such as Entity Framework it may help your application to better understand your database structure.
CREATE TABLE Categories (
  CategoryID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
  ParentID   INT NULL,
  CategoryName NVARCHAR(100) NULL,
  -- other fields as needed
 )
GO

SET IDENTITY_INSERT Categories ON
  INSERT Categories (CategoryID, ParentID, CategoryName)
  VALUES (0, NULL, Root)
  ,       (1, 0, 'Computer')
  ,       (2, 0, 'Electronic')
  ,       (3, 1, 'Lenovo')
  ,       (4, 3, 'P250')
  ,       (5, 2, 'Lise')
SET IDENTITY_INSERT Categories OFF
GO



我不打算进入C#这一侧,因为今天大多数用户确实使用某种形式的ORM,而我是一个直接的ADO人。



我可以告诉你的是你将要有一个分类课程这反映了数据库结构,你需要有一个列表/集合来处理所有类别。



搜索各种项目的帮助,我建议你的查询中有父母子类别


这篇关于Mvc嵌套类别表列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆