Skip to content

Commit 770c066

Browse files
author
luodaokai
committed
add get_chained_droplist_value method
1 parent 742b4bc commit 770c066

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

custom_field_hash.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,24 @@ def get_index_value(values, options)
291291
indexes.join(",")
292292
end
293293
end
294+
295+
# values = ["天津市","和平区"]
296+
# options = [["北京市", [["海淀区", [["知春路"]]]]], ["天津市", [["和平区"]]]]
297+
# 级联字段数组值匹配数据库options中多维数组,返回匹配的索引下标用于工单的custom_fields自定义字段保存
298+
def self.get_chained_droplist_value(value_string, field_options)
299+
v = []
300+
values = value_string.split("|")
301+
options = field_options
302+
values.each_with_index do |value, index|
303+
options.each_with_index do |a, index|
304+
if a[0] == value
305+
v << "#{index}"
306+
options = a[1]
307+
options = [] if options.nil?
308+
end
309+
end
310+
end
311+
return [false, "#{value_string} 级联数据有错误"] if values.size != v.size
312+
v = v.join(",")
313+
return [true, v]
314+
end

0 commit comments

Comments
 (0)