开发者

How to parse DOM in OPA?

I've just now started with OPA and I want to parse a DOM, but I can only get elements by the id, with Dom.get_value(#an_id) for example. What if I have a layout like the one in the chat example on the tutorials:

    <div class="line">
      <div class="user">{x.author}:</div>
      <div class="message">{x.text}</div>
    </div>

How can I get the text that is in the messag开发者_JS百科e div? I've tried Dom.get_value(Dom.select_class("line").select_class("message")), but I get this error:

    Error
    File "chat.opa", line 29, characters 49-62, (29:49-29:62 | 714-727)
    Record expression has type dom but field access expected it to have type
    { select_class: 'a; 'r.a }.


First :

Dom.get_value only works on input or textarea tags.

In your case, you should call Dom.get_text on your div.

However, if you want to get the content without wondering if you have an input/textarea or not, just use Dom.get_content

Moreover, you can't do :

Dom.select_class("line").select_class("message"))

You can do :

Dom.select_class("message")

or

Dom.select_raw(".line > .message")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜