在我们之前的C++文章“利用rating-input PreviewWidget来对事物进行评价及打分”,我们已经展示了如何使用C++来在Scope中的PrevIEw中对事物进行评价或打分。在今天的这篇文章中,我们将介绍如何在Go Scope中来做同样的事。我们可以通过这个例子来展示如何捕获在Go PrevIEw中的按钮并得到它们的action ID以进行分别的处理。
在Go文件中的PrevIEw方法中:
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 layout layout1col.AddColumn("image","header","summary","rating","actions") // Two column layout layout2col.AddColumn("image") layout2col.AddColumn("header","actions") // Three cokumn layout layout3col.AddColumn("image") layout3col.AddColumn("header","actions") layout3col.AddColumn() // Register the layouts we just created reply.RegisterLayout(layout1col,layout2col,layout3col) header := scopes.NewPrevIEwWidget("header","header") // It has Title and a subTitle propertIEs header.AddAttributeMapPing("Title","Title") header.AddAttributeMapPing("subTitle","subTitle") // define the image section image := scopes.NewPrevIEwWidget("image","image") // It has a single source property,mapped to the result's art property image.AddAttributeMapPing("source","art") // define the summary section description := scopes.NewPrevIEwWidget("summary","text") // It has a text property,mapped to the result's description property description.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 string Metadata.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,actions) } return nil}
rating := scopes.NewPrevIEwWidget("rating","rating")
func (sc *MyScope) PerformAction(result *scopes.Result,WidgetID,actionID string) (*scopes.ActivationResponse,error) { log.Printf("Perform action for Widget=%s,action=%s\n",actionID) // var scope_data interface{} var scope_data map[string]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}
在Go 文件中实现上面的PerformAction就可以捕获在PrevIEw中的按钮事件。我们在上面的代码中打印出rating及revIEw的值。
运行我们的代码:
在运行时的输出:
整个项目的源码在:git clonehttps://gitcafe.com/ubuntu/goscope_rating.git
我们可以在Terminal中:
$chmod +x *.sh
$./run.sh
$./build.sh -d
通过我们上面的脚本执行,可以编译goscope,并部署到手机中去
$./clean.sh通过上面的脚本执行,清除所有的编译的中间文件 总结
以上是内存溢出为你收集整理的在golang中如何使用rating-input来进行打分及评价全部内容,希望文章能够帮你解决在golang中如何使用rating-input来进行打分及评价所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)