Giter Site home page Giter Site logo

Comments (14)

goligo avatar goligo commented on May 30, 2024 2

Hi Trevor,

looks like you didn't look at any documentation or samples regarding databinding, but just try to put together some classes according to the JSDOC. Please do not create instances of context or bindings directly, but use the model API for that purpose, which will return bindings of the correct type which work as expected:

http://jsbin.com/gaca/62/edit

As you might have noticed there are different model implementations, but they share a common interface so that controls do not need to take care of differences in the model implementations. This common interface is defined in the abstract model base classes (in sap.ui.model).

Regards,
Malte

from openui5.

goligo avatar goligo commented on May 30, 2024

The class sap.ui.model.Binding is an abstract base class and should not be used directly. It contains the default implementation of change handling which fires a change event on any model change. Subclasses like sap.ui.model.json.JSONPropertyBinding do only fire, if their bound property value was modified.

from openui5.

matz3 avatar matz3 commented on May 30, 2024

As @goligo said, using the actual implementation (JSONPropertyBinding in this case) will work as expected. Therefore I am closing this issue.

from openui5.

trevornc avatar trevornc commented on May 30, 2024

Thank you for the update, and I will certainly use the sap.ui.model.json.JSONPropertyBinding. Can we re-open this bug on the documentation as from what I can see there is no reference to this class anywhere in the documentation, neither in the API or in the Developer Guide.

JSONTreeBinding
JSONListBinding
JSONPropertyBinding

Unless, I am looking in the wrong place for the information https://openui5.hana.ondemand.com/#search.html?q=jsonPropertyBinding.

Regards,
Trevor

from openui5.

akudev avatar akudev commented on May 30, 2024

Hmm, right... we are clarifying now whether they are intentionally missing or what's going on there. Hold on...

from openui5.

akudev avatar akudev commented on May 30, 2024

Ok, so the concrete "JSON*" classes are intentionally not documented because they should not be used directly. Instead, "PropertyBinding" etc. are documented and they are the common base classes that hide the model type specific details behind the common API.

Another running example which also uses actual controls and gets the bindings from the controls is here:
http://jsbin.com/gaca/63/edit

Regards
Andreas

from openui5.

trevornc avatar trevornc commented on May 30, 2024

Andreas, Malte,

Thank you both for the clarifications. I am not sure why I didn't grasp the binding examples I guess I was trying to understand the process purely using the API documentation.

Please feel free to make this closed.

Regards,
Trevor

from openui5.

trevornc avatar trevornc commented on May 30, 2024

Andreas, Malte,

Is it possible to attach a change listener to part of a model ( in particular a JSONModel ) for example:

   var oData = {
        myObj1 : {
            item : "Item1"
        },
        myObj2 : {
            item : "Item2",
            item2 : {
                subItem : {
                    leafItem : "Aleaf"
                }
            }
        },
        myObj3 : {
            item : "Item3",
            thing : "Thing3"
        }
    };

Is it possible to "attachChange" to /myObj2/item2 so that any changes under this node (such as "leafItem") would fire the event ?

Regards,
Trevor

from openui5.

trevornc avatar trevornc commented on May 30, 2024

Looking at the code more closely, it would appear that using bindProperty to bind to a property that is an object does not work. The problem is in the code show below. When this._getValue() refers to an object, it returns the reference to the object (in the model), this means that later when the value is compared to the model it is always the same.

var ClientPropertyBinding = PropertyBinding.extend("sap.ui.model.ClientPropertyBinding", /** @lends sap.ui.model.ClientPropertyBinding */ {

    constructor : function(oModel, sPath, oContext, mParameters){
        PropertyBinding.apply(this, arguments);
        this.oValue = this._getValue();
    }

A solution would be to detect that the returned value is an object and then clone it using the jQuery.extend functionality.

from openui5.

warstick avatar warstick commented on May 30, 2024

@goligo HI Goligo..

i am trying to track the changes in JSONModel. But i couldn't able to track the data changes.

Here is my jsonmodel data.

{
"sample1": [ {"property1": "1"}, {"property2": "1"} ],
"sample2": [ {"property1": "1"}, {"property2": "1"} ]

}

Here, i want to track the "sample1" changes. is there any way of tracking these changes ?

from openui5.

StErMi avatar StErMi commented on May 30, 2024

Is there a live example that correctly use sap.ui.model.json.JSONPropertyBinding?

from openui5.

fredericDaigle avatar fredericDaigle commented on May 30, 2024

Hi @trevornc , did you ever find a way to fire the event only when a specified node of the model is changed instead of when any part is changed?

from openui5.

subhashchaganti avatar subhashchaganti commented on May 30, 2024

Thanks , whole thread helped alot!!!

from openui5.

johnmiroki avatar johnmiroki commented on May 30, 2024

Thinking out of the box, maybe we should ditch the event based reactivity altogether and jump on the modern observability/reactivity wagon by leveraging Proxy. I am in awe when I learn about what Vue can do with method/watch/computed and intend to introduce them to UI5 ego system.

from openui5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.