mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 05:18:39 +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));
|
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;
|
||||||
@ -590,6 +591,10 @@ export class Binding {
|
|||||||
// calling off method with null as handler will remove all handlers for options.property event
|
// calling off method with null as handler will remove all handlers for options.property event
|
||||||
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 {
|
||||||
|
let specialSetter = getSpecialPropertySetter(options.property);
|
||||||
|
if (specialSetter) {
|
||||||
|
specialSetter(optionsInstance, value);
|
||||||
} else {
|
} else {
|
||||||
if (optionsInstance instanceof observable.Observable) {
|
if (optionsInstance instanceof observable.Observable) {
|
||||||
optionsInstance.set(options.property, value);
|
optionsInstance.set(options.property, value);
|
||||||
@ -598,6 +603,7 @@ export class Binding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
trace.write("Binding error while setting property " + options.property + " of " + optionsInstance + ": " + ex,
|
trace.write("Binding error while setting property " + options.property + " of " + optionsInstance + ": " + ex,
|
||||||
trace.categories.Binding,
|
trace.categories.Binding,
|
||||||
|
Reference in New Issue
Block a user