mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Merge pull request #1452 from NativeScript/nnikolov/BindingExpressionToSupportFuncs
Added support for functions with binding expressions.
This commit is contained in:
@ -938,3 +938,28 @@ export var test_BindingHitsGetterTooManyTimes = function () {
|
||||
|
||||
TKUnit.assertEqual(counter, 1, "Property getter should be hit only once!");
|
||||
}
|
||||
|
||||
export function test_SupportFunctionsInExpressions() {
|
||||
var model = new observable.Observable({
|
||||
"anyColor": "red",
|
||||
"isVisible": function () {
|
||||
return this.get("anyColor") === "red";
|
||||
}
|
||||
});
|
||||
|
||||
var bindableObj = new bindable.Bindable();
|
||||
|
||||
bindableObj.bind({
|
||||
"sourceProperty": "$value",
|
||||
"targetProperty": "test",
|
||||
"expression": "isVisible() ? 'visible' : 'collapsed'"
|
||||
}, model);
|
||||
|
||||
model.set("anyColor", "blue");
|
||||
|
||||
TKUnit.assertEqual(bindableObj.get("test"), "collapsed", "When anyColor is blue test property should be collapsed.");
|
||||
|
||||
model.set("anyColor", "red");
|
||||
|
||||
TKUnit.assertEqual(bindableObj.get("test"), "visible", "When anyColor is red test property should be visible.");
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ export class Binding {
|
||||
this.prepareContextForExpression(context, expression);
|
||||
|
||||
model[contextKey] = context;
|
||||
return exp.getValue(model, isBackConvert, changedModel);
|
||||
return exp.getValue(model, isBackConvert, changedModel ? changedModel : model);
|
||||
}
|
||||
return new Error(expression + " is not a valid expression.");
|
||||
}
|
||||
|
Reference in New Issue
Block a user