소스 검색

通知单保存

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) {
 export function clearViewModelByLookup(sender, lookup) {
     if (_.isPlainObject(lookup)) {
     if (_.isPlainObject(lookup)) {
         const parentScope = lookupScope(sender)
         const parentScope = lookupScope(sender)