大佬教程收集整理的这篇文章主要介绍了在golang中如何使用rating-input来进行打分及评价,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我们之前的C++文章“利用rating-input PreviewWidget来对事物进行评价及打分”,我们已经展示了如何使用C++来在Scope中的Preview中对事物进行评价或打分。在今天的这篇文章中,我们将介绍如何在Go Scope中来做同样的事。我们可以通过这个例子来展示如何捕获在Go Preview中的按钮并得到它们的action id以进行分别的处理。
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
$./clean.sh通过上面的脚本执行,清除所有的编译的中间文件
以上是大佬教程为你收集整理的在golang中如何使用rating-input来进行打分及评价全部内容,希望文章能够帮你解决在golang中如何使用rating-input来进行打分及评价所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。