chanjs 2.6.13 → 2.6.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/extend/art-template.js +19 -3
- package/package.json +1 -1
package/extend/art-template.js
CHANGED
|
@@ -41,13 +41,29 @@ template.defaults.imports.truncate = (str, length = 10) => {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
44
|
+
* 安全的 JSON 序列化过滤器
|
|
45
|
+
* 用于在模板中调试和显示对象内容
|
|
45
46
|
* @param {Object} obj - 要序列化的对象
|
|
47
|
+
* @param {Array} keys - 可选,只返回指定的字段
|
|
46
48
|
* @returns {string} JSON字符串
|
|
47
49
|
*/
|
|
48
|
-
template.defaults.imports.safeStringify = (obj) => {
|
|
50
|
+
template.defaults.imports.safeStringify = (obj, keys) => {
|
|
51
|
+
if (!obj) return 'null';
|
|
52
|
+
|
|
53
|
+
// 如果指定了 keys,只返回这些字段
|
|
54
|
+
if (keys && Array.isArray(keys) && keys.length > 0) {
|
|
55
|
+
const filteredObj = {};
|
|
56
|
+
keys.forEach(key => {
|
|
57
|
+
if (obj.hasOwnProperty(key)) {
|
|
58
|
+
filteredObj[key] = obj[key];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return JSON.stringify(filteredObj, null, 2);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 否则返回完整对象
|
|
49
65
|
return JSON.stringify(obj, null, 2);
|
|
50
|
-
|
|
66
|
+
};
|
|
51
67
|
|
|
52
68
|
/**
|
|
53
69
|
* Markdown 渲染过滤器
|