D3.js selection.data()可选参数

时间:2016-10-13 14:45:09

标签: d3.js

根据D3 v4 documentation <Window x:Class="Spinner.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Spinner" mc:Ignorable="d" ResizeMode="CanMinimize" SizeToContent="WidthAndHeight" Title="Scroll Spinner"> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <!-- The button exists just to have something other than the spinner be the object of focus. --> <Button Content="Reset" TabIndex="0"/> <!-- The spinner is just a scroll bar overlaying a text box (same tab indices). --> <!-- Only the scroll bar is named (in order to get its value); the text box just relfects the scroll bar's value. --> <TextBox GotFocus="TextBox_GotFocus" Grid.Row="1" Height="{Binding ElementName=SpinnerScr, Path=ActualHeight}" HorizontalAlignment="Stretch" IsReadOnly="True" TabIndex="1" Text="{Binding ElementName=SpinnerScr, Path=Value, StringFormat={}{0:####0}}" TextAlignment="Center"/> <ScrollBar x:Name="SpinnerScr" Background="Transparent" Focusable="True" Grid.Row="1" Height="20" LostFocus="SpinnerScr_LostFocus" Margin="0,3" Maximum="999" Orientation="Horizontal" SmallChange="1" TabIndex="1" Visibility="Hidden"/> <x:Code> <![CDATA[ void SpinnerScr_LostFocus(object sender, RoutedEventArgs e) { SpinnerScr.Visibility = Visibility.Hidden; } void TextBox_GotFocus(object sender, RoutedEventArgs e) { SpinnerScr.Visibility = Visibility.Visible; SpinnerScr.Focus(); } ]]> </x:Code> </Grid> </Window> using System.Windows; namespace Spinner { public partial class MainWindow : System.Windows.Window { public MainWindow() { InitializeComponent(); } } } 的函数语法为data()

这向我建议selection.data([data[, key]])datakey的可选参数。但data()总是不是必需参数吗?我知道data是可选的,如果没有指定则默认为数组索引 - 但为什么key参数是可选的,什么是不绑定DOM元素的点?

1 个答案:

答案 0 :(得分:2)

.data的所有参数都是可选的。来自docs

  

如果未指定数据,则此方法返回数据数组   选定的元素。

此外,它被写为[data[, key]],因为指定数据时 key然后成为可选参数。