question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shit API & Select dynamic Options, how to set defaultValue ???

See original GitHub issue

What problem does this feature solve?

Select dynamic Options, how to set defaultValue ???

I don’t know the first Option value, So how can I get set the default value using the first Option’s value ???


 defaultValue="???"

// I don't know the first Option value, 
// So how can I get set the default value using the first Option's value ???

What does the proposed API look like?

defaultValue={key===1}

just using key to set the defaultValue!


<Select
    allowClear
    placeholder="排序字段,支持排序组合"
    onChange={this.onSelectSortKeyChange}
    defaultActiveFirstOption
    showSearch
    defaultValue={key === 1}
    // ??? Select dynamic Options, how to set defaultValue ???
    >
    {/* 
        Select.js:630 Uncaught TypeError: Cannot read property 'type' of null
    */}
    {
        [sort_items].map(
            (sort_items) => {
                let i = 0;
                let arr = [];
                for(let key in sort_items){
                    arr.push(
                        <Option
                            key={i}
                            value={key}>
                            {
                                sort_items[key]
                            }
                        </Option>
                    )
                }
                return arr;
            }
        )
    }
</Select>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
xyzdatacommented, Aug 23, 2017

shit api!

image

4reactions
xyzdatacommented, Aug 23, 2017

Select dynamic Options & defaultValue

Select dynamic Options, how to set defaultValue ???

https://github.com/ant-design/ant-design/issues/7292

solution



    <Select
        allowClear
        placeholder="排序字段,支持排序组合"
        onChange={this.onSelectSortKeyChange}
        defaultActiveFirstOption
        showSearch
        defaultValue={Object.keys(sort_items)[0]}
        // ??? Select dynamic Options, how to set defaultValue ???
        /*
            obj = {k1: 1, k2: 2, k3: 3};
            // {k1: 1, k2: 2, k3: 3}
            Object.keys(obj)[0];
            // "k1"
            obj[Object.keys(obj)[0]];
            // 1
        */
        >
    </Select>


Read more comments on GitHub >

github_iconTop Results From Across the Web

Set initial default value in Angularjs dynamic selector
If I put "Select value" first in the List from the back end, the selector initially shows/selects the last item in the list....
Read more >
3 Ways to Set Default Value in JavaScript | SamanthaMing.com
Let's break down the 3 different ways to set Default Values using logical operator, ternary, ... Using Default Value as Function Parameter; Falsy...
Read more >
Setting Default Value In Dropdown When Using Api To Filter ...
A dropdown menu for displaying choices an elegant alternative to the native <select> element. Specify the prop name of Option which will be...
Read more >
Set a Default Value for a Dropdown Menu in Power Apps ...
In most modern apps, it's common to need to set a default choice in a dropdown menu. But how can you do this...
Read more >
Set a Custom Default Value for the Drop Down lookup Control ...
In this episode, Chino shows you how to set a custom / first value for your drop down fields that are connected to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found