Ng-zorro-antd: 在 ng-zorro-antd 中 TreeSelect树选择 的 树结点中数据中的 表示结点是否为 叶子结点的 isLeaf 字段 如果是 java 来做后台 则 违背了 《阿里巴巴Java开发手册(详尽版).pdf》第一章第一节第八点 关于 JavaBean 中 对 boolean 值的规定

Created on 16 May 2019  ·  6Comments  ·  Source: NG-ZORRO/ng-zorro-antd

Reproduction link

https://stackblitz.com/edit/angular-tfvr23

Steps to reproduce

在 ng-zorro-antd 中 TreeSelect树选择 中
当JAVA 做为后台 并且 后台返回树结构时,对于 isLeaf(标识结点是否为叶子结点的字段名) 是和 《阿里巴巴Java开发手册(详尽版).pdf》相冲突的

What is expected?

booean 字段无 is前缀

What is actually happening?

booean 字段有 is前缀

| Environment | Info |
|---|---|
| ng-zorro-antd | 7.3.3 |
| Browser | all |

Most helpful comment

手册中不推荐使用 isXxx 是因为部分 Java 框架会将 isXxx 对应成属性 xxx,从而导致属性匹配失败的问题。

JavaScript 作为弱类型语言,可以直接设置属性而不用关心类型:

entity[propName] = whateverTypeValue;

对于 getter / setter 也与 java 不同,可以做到无感知:

Object.defineProperty(entity, 'propName', {
  get() { ... },
  set(val) { ... }
});

entity[propName] = whateverTypeValue;

JS 中不会遇到 java 的序列化问题,因而也不会严格要求是否使用 is 作为前缀。

反过来,JS 中有一些规范,在 Java 中也同样不适用。例如判断是否相等需要用 === 而不是 ==null undefined delete 不推荐作为属性名等等。根据语言选择适合的规范就行了。

All 6 comments

Translation of this issue:


In the ng-zorro-antd treeSelect tree selected in the tree node, the isLeaf field in the data indicating whether the node is a leaf node is in violation of the "Alibaba Java Development Manual (detailed version) if it is java to do the background) .pdf, Chapter 1, Section 1, Section 8 on Boolean Values ​​in JavaBeans

Reproduction link

https://stackblitz.com/edit/angular-tfvr23

Steps to reproduce

TreeSelect tree selection in ng-zorro-antd
When JAVA is backed up and the backstage returns to the tree structure, the isLeaf (the name of the field identifying whether the node is a leaf node) conflicts with the Alibaba Java Development Manual (detailed version).pdf.

What is expected?

Booean field without is prefix

What is actually happening?

Booean field has is prefix

| Environment | Info |
|---|---|
| ng-zorro-antd | 7.3.3 |
| Browser | all |

image

手册中不推荐使用 isXxx 是因为部分 Java 框架会将 isXxx 对应成属性 xxx,从而导致属性匹配失败的问题。

JavaScript 作为弱类型语言,可以直接设置属性而不用关心类型:

entity[propName] = whateverTypeValue;

对于 getter / setter 也与 java 不同,可以做到无感知:

Object.defineProperty(entity, 'propName', {
  get() { ... },
  set(val) { ... }
});

entity[propName] = whateverTypeValue;

JS 中不会遇到 java 的序列化问题,因而也不会严格要求是否使用 is 作为前缀。

反过来,JS 中有一些规范,在 Java 中也同样不适用。例如判断是否相等需要用 === 而不是 ==null undefined delete 不推荐作为属性名等等。根据语言选择适合的规范就行了。

如果后端返回的数据不符合你的需求,转换只需要一句javascript代码

const listOfSampleData = [{leaf:true,data:1000},{leaf:false,data:100}];
const listOfConvertData = listOfSampleData.map(item=>{return{...item,isLeaf:item.leaf}});

如果后端返回的数据不符合你的需求,转换只需要一句javascript代码

const listOfSampleData = [{leaf:true,data:1000},{leaf:false,data:100}];
const listOfConvertData = listOfSampleData.map(item=>{return{...item,isLeaf:item.leaf}});

我知道这种可以,但是 这种操作是需要map一次,也就是遍历一次数据的,对于设计来说这些都是可以避免的。

手册中不推荐使用 isXxx 是因为部分 Java 框架会将 isXxx 对应成属性 xxx,从而导致属性匹配失败的问题。

JavaScript 作为弱类型语言,可以直接设置属性而不用关心类型:

entity[propName] = whateverTypeValue;

对于 getter / setter 也与 java 不同,可以做到无感知:

Object.defineProperty(entity, 'propName', {
  get() { ... },
  set(val) { ... }
});

entity[propName] = whateverTypeValue;

JS 中不会遇到 java 的序列化问题,因而也不会严格要求是否使用 is 作为前缀。

反过来,JS 中有一些规范,在 Java 中也同样不适用。例如判断是否相等需要用 === 而不是 ==null undefined delete 不推荐作为属性名等等。根据语言选择适合的规范就行了。

确实JS 是没必要强制要求这个,但是个人觉得,为了适配不同的规则应该可以自定义传入的数据的属性名,比如可以指定另外一个名字来作为isLeaf的替代品

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hsuanxyz picture hsuanxyz  ·  3Comments

zhouwf108 picture zhouwf108  ·  3Comments

linjianhong picture linjianhong  ·  3Comments

s01c83l picture s01c83l  ·  3Comments

bambooj picture bambooj  ·  4Comments