mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
Merge pull request #171 from NativeScript/nnikolov/CssParserErrorMessage
Binding converter run-time errors logging on console.
This commit is contained in:
@ -32,13 +32,38 @@ export function pageLoaded(args: observableModule.EventData) {
|
|||||||
model.set("toUpper", toUpperConverter);
|
model.set("toUpper", toUpperConverter);
|
||||||
model.set("testProperty", "Alabala");
|
model.set("testProperty", "Alabala");
|
||||||
|
|
||||||
|
var dateConverter = {
|
||||||
|
toView: function (value, format) {
|
||||||
|
var result = format;
|
||||||
|
var day = value.getDate();
|
||||||
|
result = result.replace("dd", month < 10 ? "0" + day : day);
|
||||||
|
var month = value.getMonth() + 1;
|
||||||
|
result = result.replace("mm", month < 10 ? "0" + month : month);
|
||||||
|
result = result.replace("yyyy", value.getFullYear());
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
toModel: function (value, format) {
|
||||||
|
var ddIndex = format.indexOf("dd");
|
||||||
|
var day = parseInt(value.substr(ddIndex, 2));
|
||||||
|
var mmIndex = format.indexOf("mm");
|
||||||
|
var month = parseInt(value.substr(mmIndex, 2));
|
||||||
|
var yyyyIndex = format.indexOf("yyyy");
|
||||||
|
var year = parseInt(value.substr(yyyyIndex, 4));
|
||||||
|
var result = new Date(year, month - 1, day);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
model.set("dateConverter", dateConverter);
|
||||||
|
model.set("testDate", new Date());
|
||||||
|
|
||||||
page.bindingContext = model;
|
page.bindingContext = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onTap(args: observableModule.EventData) {
|
export function onTap(args: observableModule.EventData) {
|
||||||
var button: buttonModule.Button = <buttonModule.Button>args.object;
|
var button: buttonModule.Button = <buttonModule.Button>args.object;
|
||||||
trace.write("tasks: " + button.bindingContext.get("tasks"), trace.categories.Test, trace.messageType.info);
|
trace.write("tasks: " + button.bindingContext.get("testDate"), trace.categories.Test, trace.messageType.info);
|
||||||
button.bindingContext.get("tasks").push("alabala");
|
//button.bindingContext.get("tasks").push("alabala");
|
||||||
}
|
}
|
||||||
|
|
||||||
//export function createPage() {
|
//export function createPage() {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded">
|
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded">
|
||||||
<StackLayout padding="7">
|
<StackLayout padding="7">
|
||||||
<TextField text="{{ tasks.length, tasks.length === 0 ? 'zero items' : tasks.length + ' items', false }}" />
|
<!--<TextField text="{{ tasks.length, tasks.length === 0 ? 'zero items' : tasks.length + ' items', false }}" />-->
|
||||||
|
<TextField text="{{ testDate, testDate | dateConverter('dd.mm.yyyy') }}" updateTextTrigger="textChanged"/>
|
||||||
|
<TextField text="{{ testDate }}" />
|
||||||
<Button text="Click" tap="onTap" />
|
<Button text="Click" tap="onTap" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</Page>
|
</Page>
|
@ -225,7 +225,13 @@ export class Binding {
|
|||||||
if (this._isExpression(this.options.expression)) {
|
if (this._isExpression(this.options.expression)) {
|
||||||
var changedModel = {};
|
var changedModel = {};
|
||||||
changedModel[this.options.sourceProperty] = value;
|
changedModel[this.options.sourceProperty] = value;
|
||||||
this.updateSource(this._getExpressionValue(this.options.expression, true, changedModel));
|
var expressionValue = this._getExpressionValue(this.options.expression, true, changedModel);
|
||||||
|
if (expressionValue instanceof Error) {
|
||||||
|
trace.write((<Error>expressionValue).message, trace.categories.Binding, trace.messageType.error);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.updateSource(expressionValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.updateSource(value);
|
this.updateSource(value);
|
||||||
@ -250,16 +256,23 @@ export class Binding {
|
|||||||
var context = this.source && this.source.get && this.source.get() || global;
|
var context = this.source && this.source.get && this.source.get() || global;
|
||||||
return exp.getValue(context, isBackConvert, changedModel);
|
return exp.getValue(context, isBackConvert, changedModel);
|
||||||
}
|
}
|
||||||
return undefined;
|
return new Error(expression + " is not a valid expression.");
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
return undefined;
|
var errorMessage = "Run-time error occured in file: " + e.sourceURL + " at line: " + e.line + " and column: " + e.column;
|
||||||
|
return new Error(errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public onSourcePropertyChanged(data: observable.PropertyChangeData) {
|
public onSourcePropertyChanged(data: observable.PropertyChangeData) {
|
||||||
if (this._isExpression(this.options.expression)) {
|
if (this._isExpression(this.options.expression)) {
|
||||||
this.updateTarget(this._getExpressionValue(this.options.expression, false, undefined));
|
var expressionValue = this._getExpressionValue(this.options.expression, false, undefined);
|
||||||
|
if (expressionValue instanceof Error) {
|
||||||
|
trace.write((<Error>expressionValue).message, trace.categories.Binding, trace.messageType.error);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.updateTarget(expressionValue);
|
||||||
|
}
|
||||||
} else if (data.propertyName === this.options.sourceProperty) {
|
} else if (data.propertyName === this.options.sourceProperty) {
|
||||||
this.updateTarget(data.value);
|
this.updateTarget(data.value);
|
||||||
}
|
}
|
||||||
@ -267,7 +280,13 @@ export class Binding {
|
|||||||
|
|
||||||
private getSourceProperty() {
|
private getSourceProperty() {
|
||||||
if (this._isExpression(this.options.expression)) {
|
if (this._isExpression(this.options.expression)) {
|
||||||
return this._getExpressionValue(this.options.expression, false, undefined);
|
var expressionValue = this._getExpressionValue(this.options.expression, false, undefined);
|
||||||
|
if (expressionValue instanceof Error) {
|
||||||
|
trace.write((<Error>expressionValue).message, trace.categories.Binding, trace.messageType.error);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return expressionValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.sourceOptions) {
|
if (!this.sourceOptions) {
|
||||||
|
Reference in New Issue
Block a user