فهرست منبع

通知单保存

liuzhuang 3 سال پیش
والد
کامیت
98e0399a4f
1فایلهای تغییر یافته به همراه22 افزوده شده و 0 حذف شده
  1. 22 0
      src/lib/systemLib.ts

+ 22 - 0
src/lib/systemLib.ts

@@ -1036,6 +1036,28 @@ class SystemEventFu {
     }
 }
 
+/**
+ * 清空 viewmodel 里下属的所有属性
+ * @param viewModel VM对象
+ * @param propertyKey 要清空的属性,可以是 "a.b.c" 这种表达模式
+ * @param ignoreProps 要忽略清空的属性名集合, 比如 ["a.b","b"]
+ */
+export function clearViewModel(viewModel, propertyKey, ignoreProps) {
+    let data = viewModel.data
+
+    if (propertyKey) {
+        data = _.get(data, propertyKey)
+    }
+
+    _.forOwn(data, (value, key) => {
+        let targetKey = propertyKey ? propertyKey + "." + key : key
+        if (ignoreProps && _.indexOf(ignoreProps, targetKey) >= 0) {
+            return
+        }
+        viewModel.set(targetKey, '')
+    })
+}
+
 export function clearViewModelByLookup(sender, lookup) {
     if (_.isPlainObject(lookup)) {
         const parentScope = lookupScope(sender)