mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Fixed adding converters to bindingContext.
This commit is contained in:
@ -567,6 +567,7 @@ export function test_BindingToDictionaryAtAppLevel() {
|
|||||||
page.bindingContext = pageViewModel;
|
page.bindingContext = pageViewModel;
|
||||||
|
|
||||||
TKUnit.assertEqual(testLabel.text, expectedValue);
|
TKUnit.assertEqual(testLabel.text, expectedValue);
|
||||||
|
TKUnit.assertTrue(testLabel.bindingContext["dict"] === undefined, "BindingContext should not contain properties from application resources.");
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.buildUIAndRunTest(createLabel(), testFunc);
|
helper.buildUIAndRunTest(createLabel(), testFunc);
|
||||||
|
@ -386,17 +386,26 @@ export class Binding {
|
|||||||
if (exp) {
|
if (exp) {
|
||||||
var context = this.source && this.source.get && this.source.get() || global;
|
var context = this.source && this.source.get && this.source.get() || global;
|
||||||
var model = {};
|
var model = {};
|
||||||
|
var addedProps = [];
|
||||||
ensureApplication();
|
ensureApplication();
|
||||||
for (var prop in application.resources) {
|
for (var prop in application.resources) {
|
||||||
if (application.resources.hasOwnProperty(prop) && !context.hasOwnProperty(prop)) {
|
if (application.resources.hasOwnProperty(prop) && !context.hasOwnProperty(prop)) {
|
||||||
context[prop] = application.resources[prop];
|
context[prop] = application.resources[prop];
|
||||||
|
addedProps.push(prop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.prepareContextForExpression(context, expression);
|
this.prepareContextForExpression(context, expression);
|
||||||
|
|
||||||
model[contextKey] = context;
|
model[contextKey] = context;
|
||||||
return exp.getValue(model, isBackConvert, changedModel ? changedModel : model);
|
let result = exp.getValue(model, isBackConvert, changedModel ? changedModel : model);
|
||||||
|
// clear added props
|
||||||
|
let addedPropsLength = addedProps.length;
|
||||||
|
for(let i = 0; i < addedPropsLength; i++) {
|
||||||
|
delete context[addedProps[i]];
|
||||||
|
}
|
||||||
|
addedProps.length = 0;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
return new Error(expression + " is not a valid expression.");
|
return new Error(expression + " is not a valid expression.");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user