Skip to content

Commit ddc68a4

Browse files
committed
get_chained_droplist_value 🚑
1 parent 759f566 commit ddc68a4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

ticket_importer.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,25 @@ def import_custom_fields(template)
353353
end
354354

355355
end
356+
357+
Class SelectField
358+
# options = [["北京市", [["海淀区", [["知春路"]]]]], ["天津市", [["和平区"]]]]
359+
# 级联字段数组值匹配数据库options中多维数组,返回匹配的索引下标用于工单的custom_fields自定义字段保存
360+
def self.get_chained_droplist_value(value_string, field_options)
361+
v = []
362+
values = value_string.split("|").map(&:strip)
363+
options = field_options
364+
values.each_with_index do |value, index|
365+
options.each_with_index do |a, index|
366+
if a[0] == value
367+
v << "#{index}"
368+
options = a[1]
369+
options = [] if options.nil?
370+
end
371+
end
372+
end
373+
return [false, "#{value_string} 级联数据有错误"] if values.size != v.size
374+
v = v.join(",")
375+
return [true, v]
376+
end
377+
end

0 commit comments

Comments
 (0)