如何在选择字段中给出值

How to give value in select field?

本文关键字:字段 选择      更新时间:2023-09-26

我正在创建一个select字段。我谷歌一下,发现我们在选择框中显示不同的字符串并得到不同的值。

http://plnkr.co/edit/I9s79qGwqw0x6hGis0JX?p =

预览

现在我使用json从这里形成插件

https://github.com/nimbly/angular-formly

当我应用所有东西时,它给出值**1,2…**像显示名称是不同的。我只是想改变选择框的值,我怎么能做到这一点?这是我的活塞

http://plnkr.co/edit/Wcvh2AMxtopPmIwpJkfi?p =

预览
$scope.formFields = [
    {
        //the key to be used in the result values {... "username": "johndoe" ... }
        key: 'username',
        //default value
        default: 'uberuser',
        type: 'text',
        label: 'Username',
        placeholder: 'johndoe',
        required: true,
        disabled: false, //default: false
        description: 'Descriptive text'
    },  {
    "key": "transportation",
    "type": "select",
    "label": "How do you get around in the city",
    "options": [
        {
            "name": "Car"
        },
        {
            "name": "Helicopter"
        }
    ]
    }
];

我需要如果我选择汽车它给出值"aadsasd"。当我选择"直升飞机"时它的值是" passdpasdpass "

在这个插件中,您可以为option传递名称和值,它将生成您在option中传递的值。这个链接https://github.com/nimbly/angular-formly/blob/master/src/directives/formly-field-select.html告诉你这个插件是如何创建选择表单的。它将选项视为服务,所以你可以像这样传递值

[
  {name: "red", value: "dgdsg"},
  {name: "white", value: "1dgsg"},
]