Added support for in expressions.

This commit is contained in:
Nedyalko Nikolov
2016-02-08 11:58:15 +02:00
parent 630daa03e9
commit 5144969ae0
2 changed files with 28 additions and 0 deletions

View File

@@ -963,3 +963,28 @@ export function test_SupportFunctionsInExpressions() {
TKUnit.assertEqual(bindableObj.get("test"), "visible", "When anyColor is red test property should be visible.");
}
export function test_$ValueSupportWithinExpression() {
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": "$value.anyColor === 'red' ? 'red' : 'blue'"
}, model);
model.set("anyColor", "blue");
TKUnit.assertEqual(bindableObj.get("test"), "blue", "When anyColor is blue test property should be blue too.");
model.set("anyColor", "red");
TKUnit.assertEqual(bindableObj.get("test"), "red", "When anyColor is red test property should be red too.");
}

View File

@@ -458,6 +458,9 @@ export class Binding {
private prepareContextForExpression(model, expression) {
var parentViewAndIndex;
var parentView;
if (expression.indexOf(bc.bindingValueKey) > -1) {
model[bc.bindingValueKey] = model;
}
if (expression.indexOf(bc.parentValueKey) > -1) {
parentView = this.getParentView(this.target.get(), bc.parentValueKey).view;
if (parentView) {