發表文章

目前顯示的是 10月, 2015的文章

[Javascript] convert-object-array-to-hash-map-indexed-by-an-attribute-value-of-the-object

var arr = [ { key : 'foo' , val : 'bar' }, { key : 'hello' , val : 'world' } ]; var result = arr . reduce ( function ( map , obj ) { map [ obj . key ] = obj . val ; return map ; }, {}); console . log ( result ); // { foo: 'bar', hello: 'world' } Note:   Array.prototype.reduce()  is IE9+, so if you need to support older browsers you will need to polyfill it. from  http://stackoverflow.com/questions/26264956/convert-object-array-to-hash-map-indexed-by-an-attribute-value-of-the-object from  https://lodash.com/docs#indexBy var keyData = [   { 'dir' : 'left' , 'code' : 97 } ,   { 'dir' : 'right' , 'code' : 100 } ] ; _. indexBy ( keyData , 'dir' ) ; // → { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } _. ind...

[MySQL] 當使用distinct/group by時產出的順序不是我們所需要

在做專案時很常會碰到要有個功能叫做 "瀏覽過的商品" 在我們系統是使用Log來做 使用Shopper_Id去Log中找出對應的商品ID,然後order by Timestamp desc 因為商品ID在Log中很容易重覆,所以可以使用distinct/group by來處理 但問題來了,明明有使用order by Timestamp desc,但順序卻不是我要的? 這是因為order by的欄位並不在我們的group by/distinct中 該如何解決? 使用order by MAX(Timestamp) desc就可以了 意思大概就是在我們Log中找Timestamp最大的來比對 更詳細的可以看國外高手的文章囉 So what is a workaround for this problem – in other words, how can we be more specific to get what we really want? Well, let’s rephrase the problem – what if we say we want to retrieve each salesperson ID sorted by their respective highest dollar amount value ( and only have each salesperson_id returned just once )? This is different than just saying that we want each distinct salesperson ID sorted by their Amount, because we are being more specific by saying that we want to sort by  their respective highest dollar amount value . Hopefully you see the difference. From: http://www.programmerinterview.com/index.php/database-sql/sql-select-distinct-a...

[Javascript] window.location 被cancel

最近再做專案時有遇到使用window.location時被cancel (透過Chrome console的Network看的) 解法目前是看到用setTimeout..如果有人有更好的方式歡迎跟小弟說一下<(_ _)> 如果有能人懂原理也歡迎告知<(_ _)> setTimeout(function(){ window.location="XXX" }, 3000); http://stackoverflow.com/questions/8566222/javascript-window-redirect-doesnt-work-in-chrome-canceled-status

[jQuery] not selector使用

因為最近在協助設計改一些效果有用到 需求是希望在 <ul class="page_nav-"> <li> <a href="/C28_sofachair.html">客廳沙發座椅</a> <div class="pagemega" style="display: none;"> <ul> <li><a href="/S35_sofa.html">皮沙發</a></li> <li><a href="/S36_sofa.html">布沙發</a></li> <li><a href="/S37_sofa.html">L型沙發/沙發組</a></li> </ul> </div> </li> <li id="except-li"> <a href="/C31_bedroom.html">臥室床組</a> <div class=""> <ul class="funlist"> <li><a href="/S54_zzzz.html" class="pagemega-seleted">單人床組/架</a></li> <li><a href="/S55_xxxxx.html" class="">雙人床組/架</a></li> <li><...