How to use Rating-input to score and evaluate in Golang

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

In our previous C + + article "using Rating-input Previewwidget to evaluate and score things," we have shown how to use C + + to evaluate or rate things in preview in scope. In this article today, we'll show you how to do the same thing in go scope. We can use this example to show how to capture the buttons in Go preview and get their action IDs for separate processing.


In the preview method in the Go file:


UNC (S-*myscope) Preview (Result *scopes. Result, metadata *scopes. Actionmetadata, reply *scopes. Previewreply, cancelled <-chan bool) error {Layout1col: = scopes. Newcolumnlayout (1) Layout2col: = scopes. Newcolumnlayout (2) Layout3col: = scopes. Newcolumnlayout (3)//single column Layoutlayout1col. AddColumn ("image", "header", "Summary", "rating", "actions")//, and/or both column Layoutlayout2col. AddColumn ("image") Layout2col. AddColumn ("header", "Summary", "rating", "actions")//three Cokumn Layoutlayout3col. AddColumn ("image") Layout3col. AddColumn ("header", "Summary", "rating", "actions") layout3col. AddColumn ()//Register The layouts we just createdreply. Registerlayout (Layout1col, Layout2col, layout3col) Header: = scopes. Newpreviewwidget ("header", "header")//It has title and a subtitle Propertiesheader. Addattributemapping ("title", "title") header. Addattributemapping ("subtitle", "subtitle")//Define the image sectionimage: = scopes. Newpreviewwidget ("image", "image")//It has a single source property, MappeD to the result ' s art propertyimage. Addattributemapping ("source", "art")//Define the summary sectiondescription: = scopes. Newpreviewwidget ("Summary", "text")//It has a Text property, mapped to the result ' s description propertydescription. Addattributemapping ("text", "description") Actions: = scopes. Newpreviewwidget ("Actions", "actions") actions. Addattributevalue ("Actions", []actioninfo{actioninfo{id: "My_action", Label: "Close"},actioninfo{id: "My_action2", Label: "Refresh"},}) Rating: = scopes. Newpreviewwidget ("rating", "Rating-input") rating. Addattributevalue ("Visible", "both") rating. Addattributevalue ("Required", "rating") var scope_data stringmetadata. Scopedata (Scope_data) If Len (Scope_data) > 0 {extra: = scopes. Newpreviewwidget ("Extra", "text") extra. Addattributevalue ("text", "Test text") reply. Pushwidgets (header, image, description, actions, rating, extra)} else {reply. Pushwidgets (header, image, description, rating, actions)}return nil}


We can see in the above text that:


Rating: = scopes. Newpreviewwidget ("rating", "Rating-input") rating. Addattributevalue ("Visible", "both") rating. Addattributevalue ("Required", "rating")


It is used to produce a rating Previewwidget: There is rating, there is review, so in the set "visible" for both.


Func (SC *myscope) performaction (Result *scopes. Result, metadata *scopes. Actionmetadata, Widgetid, ActionId string) (*scopes. Activationresponse, error) {log. Printf ("Perform Action for widget=%s, action=%s\n", Widgetid, ActionId)//var scope_data interface{}var scope_data map[st Ring]interface{}metadata. Scopedata (&scope_data) log. Println ("rating:", scope_data["rating"]) log. Println ("Review:", scope_data["Review"]) for key, value: = Range Scope_data {log. Println ("Key:", key) log. Println ("Value:", value)}if Widgetid = = "Actions" && ActionId = = "My_action" {resp: = scopes. Newactivationresponse (scopes. Activationhidedash) resp. Setscopedata ([]string{"Hello", "World"}) return resp, nil} return scopes. Newactivationresponse (scopes. Activationshowpreview), nil}


Implement the above performaction in the go file to capture the button events in preview. We print out the values of rating and review in the code above.


Run our Code:




Output at run time:




The source code for the entire project is: Git clone https://gitcafe.com/ubuntu/goscope_rating.git


We can terminal in the following:


$chmod +x *.sh


Use the above command to make the. sh file a file that can be executed


$./run.sh


From the above script, run our scope on the desktop


$./build.sh-d


With our script above, we can compile the goscope and deploy it to the phone.


$./clean.sh


Clear all the compiled intermediate files by executing the above script



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.