mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
binding to special properties fixed
This commit is contained in:
@ -455,6 +455,17 @@ export function test_parse_ShouldParseSubProperties() {
|
||||
TKUnit.assert(sw.visibility === "collapsed", "Expected result: collapsed; Actual result: " + sw.visibility + "; type: " + typeof (sw.visibility));
|
||||
};
|
||||
|
||||
export function test_parse_ShouldParseBindingToSpecialProperty() {
|
||||
var classProp = "MyClass";
|
||||
var p = <Page>builder.parse("<Page><Label class='{{ myProp }}' /></Page>");
|
||||
var obj = new observable.Observable();
|
||||
obj.set("myProp", classProp);
|
||||
p.bindingContext = obj;
|
||||
|
||||
TKUnit.assertEqual(p.content.className, classProp);
|
||||
TKUnit.assertEqual(p.content._cssClasses.length, 1);
|
||||
};
|
||||
|
||||
export function test_parse_ShouldParseBindingsWithCommaInsideSingleQuote() {
|
||||
var expected = "Hi,test"
|
||||
var bindingString = "{{ 'Hi,' + myProp }}";
|
||||
|
@ -7,6 +7,7 @@ import trace = require("trace");
|
||||
import polymerExpressions = require("js-libs/polymer-expressions");
|
||||
import bindingBuilder = require("../builder/binding-builder");
|
||||
import viewModule = require("ui/core/view");
|
||||
import {getSpecialPropertySetter} from "ui/builder/special-properties";
|
||||
|
||||
//late import
|
||||
var _appModule = null;
|
||||
@ -22,7 +23,7 @@ var bindingContextProperty = new dependencyObservable.Property(
|
||||
"bindingContext",
|
||||
"Bindable",
|
||||
new dependencyObservable.PropertyMetadata(undefined, dependencyObservable.PropertyMetadataSettings.Inheritable, onBindingContextChanged)
|
||||
);
|
||||
);
|
||||
|
||||
function onBindingContextChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var bindable = <Bindable>data.object;
|
||||
@ -211,8 +212,8 @@ export class Binding {
|
||||
// then split properties either on '.' or '['
|
||||
var parentsMatches = property.match(bindingBuilder.parentsRegex);
|
||||
result = property.replace(bindingBuilder.parentsRegex, "parentsMatch")
|
||||
.replace(/\]/g, "")
|
||||
.split(/\.|\[/);
|
||||
.replace(/\]/g, "")
|
||||
.split(/\.|\[/);
|
||||
|
||||
var i;
|
||||
var resultLength = result.length;
|
||||
@ -591,10 +592,15 @@ export class Binding {
|
||||
optionsInstance.off(options.property, null, optionsInstance.bindingContext);
|
||||
optionsInstance.on(options.property, value, optionsInstance.bindingContext);
|
||||
} else {
|
||||
if (optionsInstance instanceof observable.Observable) {
|
||||
optionsInstance.set(options.property, value);
|
||||
let specialSetter = getSpecialPropertySetter(options.property);
|
||||
if (specialSetter) {
|
||||
specialSetter(optionsInstance, value);
|
||||
} else {
|
||||
optionsInstance[options.property] = value;
|
||||
if (optionsInstance instanceof observable.Observable) {
|
||||
optionsInstance.set(options.property, value);
|
||||
} else {
|
||||
optionsInstance[options.property] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user