让用户创建自己的自定义选择菜单选项,同时保留应用程序默认值 [英] Let users create their own custom select menu options while keeping applications defaults

查看:33
本文介绍了让用户创建自己的自定义选择菜单选项,同时保留应用程序默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在处理的应用程序中,有一个选择菜单,其中包含待处理、活动、非活动等选项.我希望允许用户创建自己的自定义选项以包含在这些菜单中.他们应该被允许添加编辑和删除他们自己的自定义选项,而不是系统默认值.一个好的标准化 mysql 模式应该是什么样的?

In an application I'm working on there is a select menu which has options such as Pending, Active, Inactive. I'd like to allow users to create their own custom options to include in these menus. They should be allowed to add edit and delete their own custom options but not the system defaults. What would a good normalized mysql schema look like for this?

推荐答案

看看这个 发布,尤其是在此资源上:http://www.billsternberger.net/jquery/dynamically-add-dropdownlist-option-using-jquery/

Have a look at this post and especially at this resource: http://www.billsternberger.net/jquery/dynamically-add-dropdownlist-option-using-jquery/

它很简单,可以做你想做的事(除了删除,但这应该不难实现:))

It's very simple and does what you want (except for deleting, but that shouldn't be hard to implement :))

关于表结构,我建议为可能具有以下字段的选择条目创建一个表:

Concerning the table structure, I's suggest to have a table for the select entries that could have following fields:

select_id (int 11), value (varchar 255), added_by_user (int 1)

where added_by_user 没有指定用户,而是说明它是否是由用户添加的.在用户表中,您可以添加字段 select_id 作为外键.现在您可以判断条目是否由用户添加,如果是,由哪个用户添加.

where added_by_user does not specify the user but tells if it was added by a user. And in the users table, you could add the field select_id as a foreign key. Now you can tell, if an entry was added by a user, and if so, by which user.

这是非常基本的,但正如我所说,这只是一种方法(以及我的方法:)),你明白了.

That's pretty basic, but as I said, it's just one way of doing it (and the way I do it :)), and you get the idea.

//

如果您希望一个用户能够拥有多个条目,那么条目表当然应该包含 users_id 作为外键(而不是相反,因为它是在上述情况下):

If you want a user to be able to have more than one entry, the entries table should, of course, contain the users_id as a foreign key (and not the other way around as it is in the case above):

select_id (int 11), value (varchar 255), added_by_user (int 1), user_id (int 11)

根据 user_id 的处理方式(例如 ID = 0 的用户是 admin 或其他), added_by_user 字段在此处可能已过时.

Depending on how the user_ids are handled (e.g. user with ID = 0 is admin or something) the added_by_user field might be obsolete here.

这篇关于让用户创建自己的自定义选择菜单选项,同时保留应用程序默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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