These are chat archives for opal/opal

3rd
Oct 2017
Frederic ZINGG
@fzingg
Oct 03 2017 12:52

HI,

When i run this code:

<script type="text/ruby">

    Document.ready? do

       @obj = `[{
        "name": "Lunr",
          "text": "Like Solr, but much smaller, and not as bright."
        }, {
          "name": "React",
          "text": "A JavaScript library for building user interfaces."
        }, {
          "name": "Lodash",
          "text": "A modern JavaScript utility library delivering modularity, performance & extras."
        }]`

       puts @obj

    end

    </script>

I got the error:

Uncaught TypeError: item.$__id__ is not a function

How to access my Javascript object elements ?
Thanks.

Elia Schito
@elia
Oct 03 2017 12:56
@fzingg you can either use the console: require 'console'; $console.log @obj
or import the objects as Hash instances: require 'native'; puts @obj.map{|element| Hash.new(element)}
Frederic ZINGG
@fzingg
Oct 03 2017 13:25
@elia Tx, the second one works well.
rubyobj =  @obj.map{|element| Hash.new(element)}
puts rubyobj[0][:name]