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