利用reviews PreviewWidget在Ubuntu Scope中顯示評價等級

來源:互聯網
上載者:User

我們可以利用reviews PreviewWidget來對我們的結果進行顯示評價。比如對點評來說,如果是5星的評價,我們可以顯示5個星表示客戶對商品最高認可。


參閱我們的API的串連,我們可以看到如下的代碼:


{    PreviewWidget w1("summary", "reviews");    w1.add_attribute_value("rating-icon-empty", Variant("file:///tmp/star-empty.svg"));    w1.add_attribute_value("rating-icon-full", Variant("file:///tmp/star-full.svg"));    VariantBuilder builder;    builder.add_tuple({        {"author", Variant("John Doe")},        {"rating", Variant(3)}    });    builder.add_tuple({        {"author", Variant("Mr. Smith")},        {"rating", Variant(5)}    });    w1.add_attribute_value("reviews", builder.end());    ...}

這裡雖然使用了自己定義的圖片“rating-icon-empty”及“rating-icon-full”,但是我覺得一般不建議使用雖然可以做到定製化。原因是我們必須嚴格按照Ubuntu標準的icon來設計自己的圖片,這樣才可以使得顯示正確無誤。


結合上面的代碼,我們在我們自己的代碼中使用如下的代碼:


    PreviewWidget review("reviews", "reviews");    VariantBuilder builder;    builder.add_tuple({                          {"author", Variant("John Doe")},                          {"review", Variant("very good")},                          {"rating", Variant(3.5)}                      });    builder.add_tuple({                          {"author", Variant("Mr. Smith")},                          {"review", Variant("very poor")},                          {"rating", Variant(5)}                      });    review.add_attribute_value("reviews", builder.end());    widgets.emplace_back(review);

在這裡我們添加了一個項“review”用來表示對商品的文字評價。這裡我們沒有使用任何自訂的圖片,它預設的情況下使用的是系統自身的。


運行我們的Scope,顯示如下:


  


整個項目的源碼在: https://github.com/liu-xiao-guo/scopetemplates_review

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.