简体   繁体   English

如何通过Magento中的文本字段为属性分配多个值?

[英]how to assign multiple values to an attribute through text field in Magento?

I want to create an attribute in Magento CE, in such a way that I can assign multiple values to it through text field. 我想在Magento CE中创建一个属性,以便可以通过文本字段为其分配多个值。 I know multiple values can also be assigned using multiple select or drop-down input type. 我知道也可以使用多个选择或下拉输入类型来分配多个值。 But values that can be assigned to our attribute run into thousands so multiple select is not practical. 但是可以分配给我们属性的值会成千上万,因此多选是不切实际的。 Is there any way through which I can assign values through a text field which are then stored in a list or array which can be manipulated individually.? 有什么方法可以通过文本字段分配值,然后将其存储在可以单独操作的列表或数组中?

Without gaining more information about the specifics of what you want to do, here's a few options: 在不获取有关您想要做的细节的更多信息的情况下,这里有一些选择:

  1. Just comma-delimit your entries in the text box. 只需用逗号分隔文本框中的输入即可。 The exact value will be stored for the attribute in the DB. 该属性的确切值将存储在数据库中。 Code that uses this attribute at some point can do an $var = explode(',' $this->getAttributeName()) call on it to get a non-associative array of the values 在某个时候使用此属性的代码可以对其执行$var = explode(',' $this->getAttributeName())来获取值的非关联数组
  2. If you want to allow the selection of numerous possible values and place those into a serialized string for storage, use something like http://xoxco.com/projects/code/tagsinput/ but make the text-box hidden and supply the option tags in the form - edit the jQuery from that library to insert the tag name into the hidden text box on-click and change the color of the tag on the frontend so the user knows its been selected. 如果要允许选择许多可能的值并将它们放入序列化的字符串中进行存储,请使用类似http://xoxco.com/projects/code/tagsinput/的名称,但将文本框隐藏起来并提供选项标签在表单中-编辑该库中的jQuery,以在单击时将标签名称插入到隐藏的文本框中,并更改前端标签的颜色,以便用户知道已选择它。 At the form submit, your POST data just contains a comma-delimited string of those tag names. 在提交表单时,您的POST数据仅包含这些标签名称的逗号分隔字符串。 The same jQuery library can be slightly altered to render the chosen tags as being selected by parsing out the pre-stored attribute text using an explode(). 通过使用explode()解析出预存储的属性文本,可以对相同的jQuery库进行略微更改以将所选标签呈现为选中状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM