mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Merge pull request #1042 from NativeScript/special-props-binding
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));
|
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() {
|
export function test_parse_ShouldParseBindingsWithCommaInsideSingleQuote() {
|
||||||
var expected = "Hi,test"
|
var expected = "Hi,test"
|
||||||
var bindingString = "{{ 'Hi,' + myProp }}";
|
var bindingString = "{{ 'Hi,' + myProp }}";
|
||||||
|
@ -7,6 +7,7 @@ import trace = require("trace");
|
|||||||
import polymerExpressions = require("js-libs/polymer-expressions");
|
import polymerExpressions = require("js-libs/polymer-expressions");
|
||||||
import bindingBuilder = require("../builder/binding-builder");
|
import bindingBuilder = require("../builder/binding-builder");
|
||||||
import viewModule = require("ui/core/view");
|
import viewModule = require("ui/core/view");
|
||||||
|
import {getSpecialPropertySetter} from "ui/builder/special-properties";
|
||||||
|
|
||||||
//late import
|
//late import
|
||||||
var _appModule = null;
|
var _appModule = null;
|
||||||
@ -22,7 +23,7 @@ var bindingContextProperty = new dependencyObservable.Property(
|
|||||||
"bindingContext",
|
"bindingContext",
|
||||||
"Bindable",
|
"Bindable",
|
||||||
new dependencyObservable.PropertyMetadata(undefined, dependencyObservable.PropertyMetadataSettings.Inheritable, onBindingContextChanged)
|
new dependencyObservable.PropertyMetadata(undefined, dependencyObservable.PropertyMetadataSettings.Inheritable, onBindingContextChanged)
|
||||||
);
|
);
|
||||||
|
|
||||||
function onBindingContextChanged(data: dependencyObservable.PropertyChangeData) {
|
function onBindingContextChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
var bindable = <Bindable>data.object;
|
var bindable = <Bindable>data.object;
|
||||||
@ -211,8 +212,8 @@ export class Binding {
|
|||||||
// then split properties either on '.' or '['
|
// then split properties either on '.' or '['
|
||||||
var parentsMatches = property.match(bindingBuilder.parentsRegex);
|
var parentsMatches = property.match(bindingBuilder.parentsRegex);
|
||||||
result = property.replace(bindingBuilder.parentsRegex, "parentsMatch")
|
result = property.replace(bindingBuilder.parentsRegex, "parentsMatch")
|
||||||
.replace(/\]/g, "")
|
.replace(/\]/g, "")
|
||||||
.split(/\.|\[/);
|
.split(/\.|\[/);
|
||||||
|
|
||||||
var i;
|
var i;
|
||||||
var resultLength = result.length;
|
var resultLength = result.length;
|
||||||
@ -591,10 +592,15 @@ export class Binding {
|
|||||||
optionsInstance.off(options.property, null, optionsInstance.bindingContext);
|
optionsInstance.off(options.property, null, optionsInstance.bindingContext);
|
||||||
optionsInstance.on(options.property, value, optionsInstance.bindingContext);
|
optionsInstance.on(options.property, value, optionsInstance.bindingContext);
|
||||||
} else {
|
} else {
|
||||||
if (optionsInstance instanceof observable.Observable) {
|
let specialSetter = getSpecialPropertySetter(options.property);
|
||||||
optionsInstance.set(options.property, value);
|
if (specialSetter) {
|
||||||
|
specialSetter(optionsInstance, value);
|
||||||
} else {
|
} 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