วันอาทิตย์ที่ 17 พฤศจิกายน พ.ศ. 2556
วันพฤหัสบดีที่ 14 พฤศจิกายน พ.ศ. 2556
คำสั่ง SQL row_number() over (partition by) : oracle
เอาไว้ "แสดงลำดับ row" ของข้อมูลบางส่วน (partition) ตามเงื่อนไขที่ต้องการ เช่น
แสดงลำดับ row ของ drg_code (drg_sequence) โดยจัดเรียงตาม (หรือสัมพันธ์กับ) departmet_id
table drug_code
แสดงลำดับ row ของ drg_code (drg_sequence) โดยจัดเรียงตาม (หรือสัมพันธ์กับ) departmet_id
table drug_code
id
|
drg_code
|
department_id
|
1
|
0892
|
1
|
2
|
0694
|
1
|
3
|
0782
|
2
|
4
|
0321
|
1
|
5
|
0120
|
1
|
6
|
1001
|
1
|
7
|
0985
|
2
|
8
|
0325
|
2
|
9
|
0695
|
3
|
10
|
0127
|
4
|
11
|
0364
|
4
|
12
|
0697
|
5
|
13
|
0247
|
1
|
14
|
0324
|
1
|
15
|
0364
|
2
|
select id,
drg_code,
department_id,
row_number() over (partition by drg_code order by department_id, drg_code) drg_sequence
from drug_code
วันจันทร์ที่ 11 พฤศจิกายน พ.ศ. 2556
jQuery compute percent scroll
เมื่อเลื่อน (scroll) window มาถึง 90% แล้วให้ทำอะไรบางอย่างตามที่ต้องการ เช่น load ข้อมูลจาก server เป็นต้น
var PERCENT_SCROLL = 90; //90 pecent
var $window = $(window);
var $document = $(document);
$window.scroll(function(){
var scrollTop = $window.scrollTop();
var windowHeight = $window.height();
var documentHeight = $document.height();
var percent = 100 * (scrollTop / (documentHeight - windowHeight));
if(percent >= PERCENT_SCROLL ){
//do something ...
}
});
วันพุธที่ 6 พฤศจิกายน พ.ศ. 2556
detect jQuery Esc key up
$(document).keyup(function(){
if (event.keyCode === 27) {
//do something ...
}
});
วันจันทร์ที่ 4 พฤศจิกายน พ.ศ. 2556
คำสั่ง call และ apply javascript
call และ apply มีหน้าที่การทำงานเหมือนกัน คือ
"เอาไว้เรียกใช้งาน method javascript ที่ต้องการ โดยสามารถส่ง parameter ผ่านทาง call และ apply ไปยัง method นั้นๆ ได้"
สิ่งที่แตกต่างกันคือ
call ส่งผ่าน parameter แบบ one by one ไปยัง method ที่ถูกเรียก (ส่วนมากจะใช้ในกรณีที่รู้ parameter แบบแน่นอนตายตัว)
ส่วน apply จะส่งผ่าน parameter แบบ array ไปยัง method ที่ถูกเรียก (ใช้ในกรณีที่ parameter เป็นแบบ dynamic : http://na5cent.blogspot.com/2013/04/dynamic-callback-argument-javascript.html)
call และ apply สามารถเปลี่ยน context ของ method ที่ถูกเรียกได้ โดยการส่ง context จากภายนอกเข้าไปแทน context ภายใน
มาดูตัวอย่างการใช้งานกันดีกว่า ผมขอยกตัวอย่างง่ายๆ เพื่อง่ายต่อความเข้าใจน่ะครับ
มาดูตัวอย่างการใช้งานกันดีกว่า ผมขอยกตัวอย่างง่ายๆ เพื่อง่ายต่อความเข้าใจน่ะครับ
var Computation = function(a, b){
this.a = a || 0;
this.b = b || 0;
};
Computation.prototype.add = function(a, b){
this.a = a || this.a;
this.b = b || this.b;
return this.a + this.b;
};
Computation.prototype.minus = function(a, b){
this.a = a || this.a;
this.b = b || this.b;
return this.a - this.b;
};
การเรียกใช้แบบทั่วๆ ไป ก็ไม่มีอะไรมากครับ
สมัครสมาชิก:
บทความ (Atom)