locked
2 dependent databind functions resulting in an infinite loop RRS feed

  • Question

  • Hi guys,

    Details: LightSwitch HTML Client, VS2013, update 2

    I have price and discount fields. Each of them should be updated if the other one is changed. I am using the databind approach which results in an endless loop between the 2 databind functions. Do you have an elegant solution to this problem. A global flag seems to be one possible solution (although I am not able to make it work yet).

    Regards,
    Martin


    Thursday, August 28, 2014 7:11 PM

Answers

  • Martin,

    Could you put some logic inside the dataBind callback function which conditionally updates Price & Discount only when they should change?

    For example(air-code not tested):

    myapp.myScreenName.Discount_postRender(contenItem,element){
    	contentItem.dataBind("Value",function(newValue){
    	//if Discount has a value
    	if (newValue){
    		var newPrice;
    		//calculate new price as ListPrice minus Discount
    		newPrice = contentItem.Screen.myEntityName.ListPrice.Value - newValue;
    			//if price not equal to newPrice then update price
    			if (contentItem.Screen.myEntityName.Price.Value != newPrice){
    				contentItem.Screen.myEntityName.Price.Value = newPrice
    			}
    	}
    	});
    }

    HTH,

    Josh

    Friday, August 29, 2014 12:57 PM

All replies

  • Martin,

    Could you put some logic inside the dataBind callback function which conditionally updates Price & Discount only when they should change?

    For example(air-code not tested):

    myapp.myScreenName.Discount_postRender(contenItem,element){
    	contentItem.dataBind("Value",function(newValue){
    	//if Discount has a value
    	if (newValue){
    		var newPrice;
    		//calculate new price as ListPrice minus Discount
    		newPrice = contentItem.Screen.myEntityName.ListPrice.Value - newValue;
    			//if price not equal to newPrice then update price
    			if (contentItem.Screen.myEntityName.Price.Value != newPrice){
    				contentItem.Screen.myEntityName.Price.Value = newPrice
    			}
    	}
    	});
    }

    HTH,

    Josh

    Friday, August 29, 2014 12:57 PM
  • Hi Josh,

    Great advice, thank you.

    Martin

    Saturday, August 30, 2014 1:36 PM