将'this'值传递给Dart中的另一个函数并调用一些方法

时间:2016-03-03 15:19:39

标签: function delegates dart parameter-passing

这种情况有可能发生。第1类:

    class AppComponent implements OnInit  {
      AppComponent() {
        Class2 pippo = new Class2()
        pippo.passAppComponent(this);
      }

      void printHelloInAppComponent(){
        print('hello');
      }
    }

第2课:

  class Class2  {
    func passAppComponent(dynamic scope) {
      scope.printHelloInAppComponent();
    }
  }

如果我尝试这个,我会接受这个错误:

  

EXCEPTION:NoSuchMethodError:找不到方法:'$ indexSet'(C.JSNull_methods。$ indexSet不是函数)[null]

1 个答案:

答案 0 :(得分:1)

您的示例几乎可以

<ItemsControl.ItemTemplate>
    <DataTemplate>
        <Canvas>
            <Path StrokeThickness="2.0" Stroke="Black" Data="{Binding LineGeometry}" />

            <ItemsControl ItemsSource="{Binding Points}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Canvas/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>

                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Path StrokeThickness="1.0" Stroke="Black" Fill="MistyRose">
                            <Path.Data>
                                <EllipseGeometry
                                    Center="{Binding
                                        Converter={StaticResource LinePointConverter}}"
                                    RadiusX="4" RadiusY="4"/>
                            </Path.Data>
                        </Path>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Canvas>
    </DataTemplate>
</ItemsControl.ItemTemplate>

DartPad

中试用