如何代码获取下拉列表标题?原创
3人赞赏了该文章
3,437次浏览
编辑于2021年04月12日 10:38:18
/** * @param fromMark 表单标识 * @param fieldMark 字段标识 * @return Map<String, Object>下拉列表键值对,key为下拉值,value为下拉标题(多语言) */ public static Map<String, Object> getDownList(String fromMark, String fieldMark) { DynamicObject dynamicObject = BusinessDataServiceHelper.newDynamicObject(fromMark); ComboProp iDataEntityProperty = (ComboProp) dynamicObject.getDataEntityType().getProperties().get(fieldMark); HashMap<String, Object> mapSetResult = new HashMap<>(16); for (ValueMapItem comboItem : iDataEntityProperty.getComboItems()) { String key = comboItem.getValue(); LocaleString value = comboItem.getName(); mapSetResult.put(key, value); } return mapSetResult; } /** * @param fromMark 表单标识 * @param entryMark 单据体标识 * @param fieldMark 单据体内字段标识 * @return Map<String, Object>下拉列表键值对,key为下拉值,value为下拉标题(多语言) */ public static Map<String, Object> getDownListFromEntry(String fromMark, String entryMark, String fieldMark) { DynamicObject dynamicObject = BusinessDataServiceHelper.newDynamicObject(fromMark); DynamicObjectType dynamicObjectType = dynamicObject.getDynamicObjectCollection(entryMark).getDynamicObjectType(); // 单据体动态对象 DynamicObject entryDynamicOperationsObject = new DynamicObject(dynamicObjectType); ComboProp iDataEntityProperty = (ComboProp) entryDynamicOperationsObject.getDataEntityType().getProperties().get(fieldMark); HashMap<String, Object> mapSetResult = new HashMap<>(16); for (ValueMapItem comboItem : iDataEntityProperty.getComboItems()) { String key = comboItem.getValue(); LocaleString value = comboItem.getName(); mapSetResult.put(key, value); } return mapSetResult; } /** * 获取下拉列表数据 * * @param fromMark 表单标识 * @param fieldMark 字段标识 * @return json字符串 */ private static String getDownListData(String fromMark, String fieldMark) { String cacheKey = "T_META_ENTITY/".concat(fromMark).concat("/").concat(fieldMark).concat("/DownList/11"); // 从缓存中取出 DistributeSessionlessCache cache = CacheFactory.getCommonCacheFactory().getDistributeSessionlessCache(); String data = cache.get(cacheKey); // 缓存中不存在时 if (data == null || data.isEmpty()) { SqlBuilder sqlBuilder = new SqlBuilder(); sqlBuilder.append("SELECT FDATA FROM T_META_ENTITY WHERE FNUMBER = ? AND FKEY = ? AND FTYPE = 11", fromMark, fromMark); data = DB.query(DBRoute.of("sys"), sqlBuilder, resultSet -> { if (resultSet.next()) { return resultSet.getString(1); } return null; }); // 放入缓存 if (data != null) { cache.put(cacheKey, data, 100); } } return data; } private static HashMap<String, Object> getDownList(Map<String, Object> map, String fieldMark) { HashMap<String, Object> mapResult = new HashMap<>(16); JSONArray properties = (JSONArray) map.get("Properties"); for (Object property : properties) { JSONObject property1 = (JSONObject) property; if (fieldMark.equals(property1.getString("Name")) && "ComboProp".equals(property1.getString("_Type_"))) { JSONArray comboItems = property1.getJSONArray("ComboItems"); for (int i = 0; i < comboItems.size(); i++) { JSONObject jsonObject = comboItems.getJSONObject(i); mapResult.put(jsonObject.getString("Value"), jsonObject.getJSONObject("Name")); } } } return mapResult; }
前两个就已经适用了,如果想要直接处理成对应的语言返回,就需要自己处理了
赞 3
3人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读