最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。
We can use JavaScript’s Use We can reconstruct the above instance into a component that receives array parameters and assigns one for each list element Of an element When the element is not determined If the list can be reordered, we do not recommend using an index for sorting, as this can cause rendering to become slow. Of the element For example, if you extract a When you are in Used in array elements {post.content} <Post key={post.id} id={post.id} title={post.title} /> ); In the above example, the Post component can read In the above example, we declare a separate JSX allows you to embed any expression in curly braces, so we can use the Doing so can sometimes make your code clearer, but sometimes this style can be abused. As in JavaScript, when you need to extract a variable for readability is entirely up to you. But remember, if a map() method to create a list. 3.10.1. React instance ¶
map() method traverses the array to generate a list of numbers 1 to 5:constnumbers=[1,2,3,4,5];constlistItems=numbers.map((numbers)=> <li>{numbers}li>);ReactDOM.render(<ul>{listItems}ul>,document.getElementById('example'));
key otherwise, there will be a warning a key should be provided for list items which means it needs to be included key : React instance ¶
functionNumberList(props){constnumbers=props.numbers;constlistItems=numbers.map((number)=> <likey={number.toString()}>{number}li>);return(<ul>{listItems}ul>);}constnumbers=[1,2,3,4,5];ReactDOM.render(<NumberListnumbers={numbers}/>,document.getElementById('example'));
3.10.2. Keys ¶
Keys can help when some elements in the DOM are added or deleted React identify which elements have changed. So you should assign a definite identity to each element in the array. const numbers = [1, 2, 3, 4, 5]; const listItems = numbers.map((number) => <li key={number.toString()}> {number} li> );
key is preferable that this element has a unique string in the list. Usually, we use the id as an element key : const todoItems = todos.map((todo) => <li key={todo.id}> {todo.text} li> );
id can use his serial number index index as key : const todoItems = todos.map((todo, index) => // Only used when there is no definite ID <li key={index}> {todo.text} li> );
3.10.3. Extract components with keys ¶
key it only makes sense when it is compared to its sibling node. ListItem components, you should put key the one saved in the array ListItem in the component on the element. 3.10.4. A false demonstration. ¶
function ListItem(props) { const value = props.value; return ( // Wrong! You don't need to specify a key here: {listItems}
); } const numbers = [1, 2, 3, 4, 5]; ReactDOM.render( 3.10.5. The correct use of key ¶
React instance ¶
functionListItem(props){//By the way! There is no need to specify a key here: return{listItems}
);} constnumbers=[1,2,3,4,5];ReactDOM.render( map() method, you’d better always remember to add a unique key . 3.10.6. Of the element
key among his brother elements, it should be unique. ¶ key should be unique among his brothers. However, they do not need to be globally unique. When we generate two different arrays, we can use the same key. React instance ¶
functionBlog(props){constsidebar=({props.posts.map((post)=>
{post.title}
{content}<p> <code class="docutils literal notranslate"> <span class="pre"> key </span> </code> will serve as a hint to React, but will not be passed on to your components. If you need to use and <code class="docutils literal notranslate"> <span class="pre"> key </span> </code> the same value, pass it as an attribute: </p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="n">const</span> <span class="n">content</span> <span class="o">=</span> <span class="n">posts</span><span class="o">.</span><span class="n">map</span><span class="p">((</span><span class="n">post</span><span class="p">)</span> <span class="o">=></span> props.id , but cannot be read out props.key .
3.10.7. Embed in jsx
map() ¶ listItems variable and include it in the JSX: function NumberList(props) { const numbers = props.numbers; const listItems = numbers.map((number) => <ListItem key={number.toString()} value={number} /> ); return ( <ul> {listItems} ul> ); }
map() is used in the following ways: React instance ¶
functionNumberList(props){constnumbers=props.numbers;return(<ul>{numbers.map((number)=> <ListItemkey={number.toString()}value={number}/>)}ul>);}
map() with too many levels of nesting, you can extract the components.