KRL and Yahoo Local Search

I am trying to use Yahoo Local Search in a Kynetx app.

ruleset avogadro {
  meta {
    name "yahoo-local-ruleset"
    description "use results from Yahoo local search"
    author "randall bohn"
    key yahoo_local "get-your-own-key"
  }
  dispatch { domain "example.com"}
  global {
    datasource local:XML <- "http://local.yahooapis.com/LocalSearchService/V3/localsearch";
  }

  rule add_list {
    select when pageview ".*" setting ()
    pre {
      ds = datasource:local("?appid=#{keys:yahoo_local()}&query=pizza&zip=#{zip}&results=5");
      rs = ds.pick("$..Result");
    }
    append("body","<ul id='my_list'></ul>");
    always {
      set ent:pizza rs;
    }
  }

  rule add_results {
    select when pageview ".*" setting ()
    foreach ent:pizza setting pizza
    pre {
      title = pizza.pick("$..Title");
    }
    append("#my_list", "<li>#{title}</li>");
  }
}

The list I'm ending on

. [object Object]

and 'title' has

{'$t' => 'Pizza Shop 1'}

I canโ€™t figure out how to get just the name. It looks like the โ€œtext contentโ€ from the original XML file is being converted to {'$ t' => 'text content'}, and the '$ t' gives problems for selection ().

+3
source share
2 answers

When XML data sources and datasets are converted to JSON, the text value in the XML node is assigned $ t. You can select the title text by changing the select statement in the preliminary block to

title = pizza.pick("$..Title.$t");

Try this and see if this solves your problem.


Side notes on things not related to your question:

1) , , . .

2) , AppBuilder . ,

ruleset avogadro {

ruleset a60x304 {

3)

setting ()

select,

+4

, ( "$.. Title. $t" ) . , . , , .

name = pizza.pick("$..Title.$t");
city = pizza.pick("$..City.$t");
phone = pizza.pick("$..Phone.$t");
list_item = "<li>#{name}/#{city} #{phone}</li>"

, !

+3

Source: https://habr.com/ru/post/1782142/


All Articles