How to Bind the Property of an Instance?

softshipper

I created an array of objects:

buildPayerModel: function() {
    return [
        new SalesPayer("000", "2333", "033.433", "CHF"),
        new SalesPayer("000", "2333", "033.433", "CHF"),
        new SalesPayer("000", "2333", "033.433", "CHF")
    ];
}

and as a model:

this.getView().setModel(this.buildPayerModel(), "Sales")

Now I want to show the data in Table as the following:

<Table id="SalesView" inset="false" items="{ path: '/Sales' }">
    <headerToolbar>
        <Toolbar>
            <Title text="Statistics" level="H2"/>
        </Toolbar>
    </headerToolbar>
    <columns>
        <Column width="12em">
            <Text text="Payer"/>
        </Column>
        <Column minScreenWidth="Tablet" demandPopin="true">
            <Text text="Name"/>
        </Column>
        <Column minScreenWidth="Tablet" demandPopin="true" hAlign="End">
            <Text text="Net Value"/>
        </Column>
        <Column hAlign="End">
            <Text text="Currency"/>
        </Column>
    </columns>
    <items>
        <ColumnListItem>
            <cells>
                <ObjectIdentifier title="{Sales.id}"/>
                <Text text="{Sales.name}"/>
                <Text text="{Sales.name}"/>
                <Text text="{Sales.name}"/>
            </cells>
        </ColumnListItem>
    </items>
</Table>

How to access the property of the instance?

Boghyon Hoffmann
  1. Your buildPayerModel() is not building a model.
  2. The API setModel awaits a "subclass" of sap.ui.model.Model (not an array), and a corresponding model name ("Sales" in your case).
  3. A short binding syntax looks as follows: "{modelName>/propertyName}".
    • The binding is defined inside the curly brackets: { ... }
    • The > is needed when there is a model name.
    • The / at the beginning (right after possible >) indicates absolute binding syntax
    • Without / at the beginning --> "{modelName>childPropertyName}" indicates relative binding syntax. It is relative because such binding cannot be resolved without given context.

Given JSONModel for the "Sales", and a SalesPayer instance contains direct properties such as name and id, here is a fix for you:

buildPayerModel: function() {
    return new /*sap.ui.model.json.*/JSONModel([
        new SalesPayer("000", "2333", "033.433", "CHF"),
        new SalesPayer("000", "2333", "033.433", "CHF"),
        new SalesPayer("000", "2333", "033.433", "CHF")
    ]);
},

Somewhere in the same controller:

this.getView().setModel(this.buildPayerModel(), "Sales")

XMLView:

<Table id="SalesView" inset="false" items="{Sales>/}">
    <headerToolbar>
        <Toolbar>
            <Title text="Statistics" level="H2"/>
        </Toolbar>
    </headerToolbar>
    <columns>
        <Column width="12em">
            <Text text="Payer"/>
        </Column>
        <Column minScreenWidth="Tablet" demandPopin="true">
            <Text text="Name"/>
        </Column>
        <Column minScreenWidth="Tablet" demandPopin="true" hAlign="End">
            <Text text="Net Value"/>
        </Column>
        <Column hAlign="End">
            <Text text="Currency"/>
        </Column>
    </columns>
    <items>
        <ColumnListItem>
            <cells>
                <ObjectIdentifier title="{Sales>id}"/>
                <Text text="{Sales>name}"/>
                <Text text="{Sales>name}"/>
                <Text text="{Sales>name}"/>
            </cells>
        </ColumnListItem>
    </items>
</Table>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to bind textblock with property

From Dev

How to Bind Attached Property

From Dev

How to bind dynamic property?

From Dev

How to bind a ContentView to a property?

From Dev

WPF Bind ItemSource to Property of Instance in Array

From Dev

How to bind to a property in view but not in viewmodel?

From Dev

How to bind property using a formatter

From Dev

How to bind a textbox to class Property

From Dev

How to bind control to object property?

From Dev

How to bind property of a ObservableCollection in XAML

From Dev

How to bind a Promise to a component property?

From Dev

How to bind to attached property in UWP?

From Dev

How to bind control to object property?

From Dev

How to bind ComboBox to ObservableCollection property?

From Dev

How to bind checkBox to a boolean property?

From Dev

How to bind user control property to other property?

From Dev

How to add a property to the instance of Script?

From Dev

How to bind to a Service that was started by another instance of the application

From Dev

How to bind a Java Supplier to an instance of an object?

From Dev

How can I bind to the Center property of an EllipseGeometry?

From Dev

How to bind collection dependency property in UserControl

From Dev

How to bind properly to a service property in AngularJS?

From Dev

How to Bind to Another Control Property in WPF

From Dev

How to bind ItemsSource to ObservableCollection Property of the parent Window?

From Dev

How to bind to a nested DataList using a property collection

From Dev

How to bind data to a control's Visibility property

From Dev

How to bind property on parent object with knockoutjs?

From Dev

WPF DataGrid, How to bind property on custom DataGridColumn

From Dev

How to bind NavigateUrl property of Hyperlink dynamically

Related Related

  1. 1

    How to bind textblock with property

  2. 2

    How to Bind Attached Property

  3. 3

    How to bind dynamic property?

  4. 4

    How to bind a ContentView to a property?

  5. 5

    WPF Bind ItemSource to Property of Instance in Array

  6. 6

    How to bind to a property in view but not in viewmodel?

  7. 7

    How to bind property using a formatter

  8. 8

    How to bind a textbox to class Property

  9. 9

    How to bind control to object property?

  10. 10

    How to bind property of a ObservableCollection in XAML

  11. 11

    How to bind a Promise to a component property?

  12. 12

    How to bind to attached property in UWP?

  13. 13

    How to bind control to object property?

  14. 14

    How to bind ComboBox to ObservableCollection property?

  15. 15

    How to bind checkBox to a boolean property?

  16. 16

    How to bind user control property to other property?

  17. 17

    How to add a property to the instance of Script?

  18. 18

    How to bind to a Service that was started by another instance of the application

  19. 19

    How to bind a Java Supplier to an instance of an object?

  20. 20

    How can I bind to the Center property of an EllipseGeometry?

  21. 21

    How to bind collection dependency property in UserControl

  22. 22

    How to bind properly to a service property in AngularJS?

  23. 23

    How to Bind to Another Control Property in WPF

  24. 24

    How to bind ItemsSource to ObservableCollection Property of the parent Window?

  25. 25

    How to bind to a nested DataList using a property collection

  26. 26

    How to bind data to a control's Visibility property

  27. 27

    How to bind property on parent object with knockoutjs?

  28. 28

    WPF DataGrid, How to bind property on custom DataGridColumn

  29. 29

    How to bind NavigateUrl property of Hyperlink dynamically

HotTag

Archive