Module: Extjsizable::CoreExt::Array::ExtJs::InstanceMethods

Defined in:
lib/extjsizable/core_ext/array/extjs.rb

Instance Method Summary collapse

Instance Method Details

#to_extjs(options = {}) ⇒ Object

Creates a JSON object by specifying which attributes we want to be shown. Ej: { ‘total’ : 2,

'data' : [
   { 'id' : 1, :nombre : 'Juan'  },
   { 'id' : 2, :nombre : 'Pedro' }
 ]

}



24
25
26
27
28
29
30
31
32
# File 'lib/extjsizable/core_ext/array/extjs.rb', line 24

def to_extjs(options = {})
  array_json_data = as_json(options)

  if ::Array.dasherize_keys?
    array_json_data.map! { |h| dasherize_hash_keys(h) }
  end

  { :total => (options.delete(:total) || self.length), :data => array_json_data }.with_indifferent_access
end