mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Added support for in expressions.
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user