Commit aed88050 authored by rockyl's avatar rockyl

增加数据绑定的索引支持

parent d0c4741f
...@@ -1762,7 +1762,7 @@ ...@@ -1762,7 +1762,7 @@
return !isNaN(v) && v !== null && v !== undefined; return !isNaN(v) && v !== null && v !== undefined;
} }
var ESCAPE_REG_EXP = /\$\{[\u4e00-\u9fa5_a-zA-Z0-9]+\}/g; var ESCAPE_REG_EXP = /\$\{[\u4e00-\u9fa5_a-zA-Z0-9\|]+\}/g;
var linkedFlag = '$_linked_$'; var linkedFlag = '$_linked_$';
var nodeScheme = 'node://'; var nodeScheme = 'node://';
function arrayFind(arr, callback) { function arrayFind(arr, callback) {
...@@ -2109,10 +2109,15 @@ ...@@ -2109,10 +2109,15 @@
var result = str; var result = str;
for (var _i = 0, escapes_1 = escapes; _i < escapes_1.length; _i++) { for (var _i = 0, escapes_1 = escapes; _i < escapes_1.length; _i++) {
var escape = escapes_1[_i]; var escape = escapes_1[_i];
var watcher = this.getWatcher(escape); var args = escape.split('|');
var name = args[0];
var watcher = this.getWatcher(name);
try { try {
var data = this.getDataByPath(watcher.path, true); var data = this.getDataByPath(watcher.path, true);
result = result.replace(new RegExp('\\$\\{' + escape + '\\}', 'g'), data); if (args[1] !== undefined) {
data = data[args[1]];
}
result = result.replace(new RegExp('\\$\\{' + escape.replace(/\|/g, '\\|') + '\\}', 'g'), data);
} }
catch (e) { catch (e) {
} }
...@@ -12163,8 +12168,10 @@ ...@@ -12163,8 +12168,10 @@
this._escapes.splice(0); this._escapes.splice(0);
for (var _i = 0, matchResult_1 = matchResult; _i < matchResult_1.length; _i++) { for (var _i = 0, matchResult_1 = matchResult; _i < matchResult_1.length; _i++) {
var item = matchResult_1[_i]; var item = matchResult_1[_i];
var eventName = item.substr(2, item.length - 3); var escape = item.substr(2, item.length - 3);
this._escapes.push(eventName); var args = escape.split('|');
var eventName = args[0];
this._escapes.push(escape);
dataCenter.addEventListener(eventName, this.onDataMutated, this); dataCenter.addEventListener(eventName, this.onDataMutated, this);
this._registeredEvents.push(eventName); this._registeredEvents.push(eventName);
} }
...@@ -12203,8 +12210,10 @@ ...@@ -12203,8 +12210,10 @@
this._escapes.splice(0); this._escapes.splice(0);
for (var _i = 0, matchResult_1 = matchResult; _i < matchResult_1.length; _i++) { for (var _i = 0, matchResult_1 = matchResult; _i < matchResult_1.length; _i++) {
var item = matchResult_1[_i]; var item = matchResult_1[_i];
var eventName = item.substr(2, item.length - 3); var escape = item.substr(2, item.length - 3);
this._escapes.push(eventName); var args = escape.split('|');
var eventName = args[0];
this._escapes.push(escape);
dataCenter.addEventListener(eventName, this.onDataMutated, this); dataCenter.addEventListener(eventName, this.onDataMutated, this);
this._registeredEvents.push(eventName); this._registeredEvents.push(eventName);
} }
......
This diff is collapsed.
...@@ -72,10 +72,15 @@ export class DataCenter extends EventDispatcher { ...@@ -72,10 +72,15 @@ export class DataCenter extends EventDispatcher {
formatString(str, escapes) { formatString(str, escapes) {
let result = str; let result = str;
for (let escape of escapes) { for (let escape of escapes) {
let watcher = this.getWatcher(escape); let args = escape.split('|');
let name = args[0];
let watcher = this.getWatcher(name);
try { try {
let data = this.getDataByPath(watcher.path, true); let data = this.getDataByPath(watcher.path, true);
result = result.replace(new RegExp('\\$\\{' + escape + '\\}', 'g'), data); if(args[1] !== undefined){
data = data[args[1]];
}
result = result.replace(new RegExp('\\$\\{' + escape.replace(/\|/g, '\\|') + '\\}', 'g'), data);
} catch (e) { } catch (e) {
} }
......
...@@ -56,8 +56,10 @@ export class Image extends Sprite { ...@@ -56,8 +56,10 @@ export class Image extends Sprite {
this._originText = value; this._originText = value;
this._escapes.splice(0); this._escapes.splice(0);
for (let item of matchResult) { for (let item of matchResult) {
let eventName = item.substr(2, item.length - 3); let escape = item.substr(2, item.length - 3);
this._escapes.push(eventName); let args = escape.split('|');
let eventName = args[0];
this._escapes.push(escape);
dataCenter.addEventListener(eventName, this.onDataMutated, this); dataCenter.addEventListener(eventName, this.onDataMutated, this);
this._registeredEvents.push(eventName); this._registeredEvents.push(eventName);
} }
......
...@@ -26,8 +26,10 @@ export class Label extends TextField { ...@@ -26,8 +26,10 @@ export class Label extends TextField {
this._originText = value; this._originText = value;
this._escapes.splice(0); this._escapes.splice(0);
for (let item of matchResult) { for (let item of matchResult) {
let eventName = item.substr(2, item.length - 3); let escape = item.substr(2, item.length - 3);
this._escapes.push(eventName); let args = escape.split('|');
let eventName = args[0];
this._escapes.push(escape);
dataCenter.addEventListener(eventName, this.onDataMutated, this); dataCenter.addEventListener(eventName, this.onDataMutated, this);
this._registeredEvents.push(eventName); this._registeredEvents.push(eventName);
} }
......
...@@ -4,7 +4,7 @@ import {registerScriptDef} from ".."; ...@@ -4,7 +4,7 @@ import {registerScriptDef} from "..";
* Created by rockyl on 2019-11-08. * Created by rockyl on 2019-11-08.
*/ */
export const ESCAPE_REG_EXP = /\$\{[\u4e00-\u9fa5_a-zA-Z0-9]+\}/g; export const ESCAPE_REG_EXP = /\$\{[\u4e00-\u9fa5_a-zA-Z0-9\|]+\}/g;
export const linkedFlag = '$_linked_$'; export const linkedFlag = '$_linked_$';
export const nodeScheme = 'node://'; export const nodeScheme = 'node://';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment