From 721b0960b02a416d171556e8de6543563f0f3cdf Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 19 Oct 2022 20:36:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?KERNEL-13158:=20=E4=BC=98=E5=8C=96=E4=B8=8B?= =?UTF-8?q?useContext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/fix/fix.compact.js | 4 ++-- examples/useContext.html | 21 +++++++++++++++++++-- src/core/4.widget.js | 7 ++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/dist/fix/fix.compact.js b/dist/fix/fix.compact.js index df02143b6..6179d484b 100644 --- a/dist/fix/fix.compact.js +++ b/dist/fix/fix.compact.js @@ -78,7 +78,7 @@ }, options); }; - function findStore (widget) { + BI.Widget.findStore = function findStore (widget) { if (target != null) { return target; } @@ -110,7 +110,7 @@ return true; } if (this._store) { - var store = findStore(this.options.context || this._parent || this.options.element || this._context); + var store = BI.Widget.findStore(this.options.context || this._parent || this.options.element || this._context); if (store) { pushTarget(store); needPop = true; diff --git a/examples/useContext.html b/examples/useContext.html index e7213e10d..b3cb40f7f 100644 --- a/examples/useContext.html +++ b/examples/useContext.html @@ -5,12 +5,13 @@ - - + + @@ -99,6 +100,22 @@ ref: function (_ref) { child = _ref; } + }, { + type: "bi.time_periods", + width: 400, + height: 24, + value: { + start: { + hour: 7, + minute: 3, + second: 16 + }, + end: { + hour: 21, + minute: 3, + second: 35 + } + } }] }; }; diff --git a/src/core/4.widget.js b/src/core/4.widget.js index 058015c32..9910f010f 100644 --- a/src/core/4.widget.js +++ b/src/core/4.widget.js @@ -902,8 +902,9 @@ }; BI.useContext = function (inject) { - if (BI.Model.target) { - var vm = BI.Model.target; + // 通过组件找最近的store + var vm = BI.Widget.findStore(BI.Widget.current); + if (vm) { if (inject) { if (vm.$$computed && inject in vm.$$computed) { return vm; @@ -923,7 +924,7 @@ return null; } } - return BI.Model.target; + return vm; }; BI.watch = function (vm, watch, handler) { From 5ed8b8e2eeca38b1b43d9dbbf2ac55383b559c47 Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 19 Oct 2022 20:39:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?KERNEL-13158:=20=E4=BC=98=E5=8C=96=E4=B8=8B?= =?UTF-8?q?useContext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/useContext.html | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/useContext.html b/examples/useContext.html index a82442a72..4ed6c9661 100644 --- a/examples/useContext.html +++ b/examples/useContext.html @@ -5,11 +5,13 @@ - + + @@ -98,6 +100,18 @@ ref: function (_ref) { child = _ref; } + }, { + type: "bi.dynamic_date_combo", + supportDynamic: false, + width: 200, + value: { + type: 1, + value: { + year: 2012, + month: 3, + day: 15 + } + } }] }; };