[英]Registering a click event with Sammy
我試圖用我的Sammy驅動的應用程序創建以下行為:
該圖像描述了一個畫廊視圖,並通過Sammy和模板框架Handlebars創建 。 每個元素都有以下模板:
<article class="gallery-item">
<img src="{{url_thumb}}" alt="{{title}}" id="image-{{id}}" />
</article>
左邊的勃艮第彩色方塊(2)應該顯示左邊的粉紅色雙胞胎的大版本。
如何連接事件,以便當我單擊帶有'class-item'類的元素時,右邊的圖像會被更改?
如果您按照此博客文章中的說明構建應用程序: mvc med sammy og handlebars 。 您可以制作圖庫項目視圖和圖庫視圖。 圖庫視圖將包含圖庫項目視圖和左側圖像的預覽視圖。 然后需要在jQuery的幫助下附加一個click事件監聽器。
像這樣的東西:
var that = this;
$(".gallery-item").on(function(e) {
that.previewView.showImage("send in the url to the image that where clicked on,
or a model containing the url or whatever you like!:)");
}
有關jQuery:on如何工作的更多信息,請查看jQuery API:ON
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.