length, size và count trong Active Record rails

length, size và count trong Active Record rails

Trong ruby, phương thức length và size đều như nhau và đều đếm số phần tử có trong array hoặc hash. array = [3, 4, 5] puts "array length: #{array.length}" puts "array size: " + array.size.to_s hash = { a: 3, b: 4, c: 5, d:6 } puts "hash length: " + hash.length.to_s puts "hash size: #{hash.size} " Đoạn code trên sẽ cho ra kết quả:  array length: 3 array size: 3 hash length: 4 hash size: 4   Trong ActiveRecord, khi đếm số phần tử của một dữ liệu quan hệ thì có thêm phương thức count nhưng 3 ph...

Cuộn selected value lên đỉnh

Cuộn selected value lên đỉnh

    Ví dụ khi chọn dropdown một thẻ select ta được như sau:   Giá trị 18時 đang được đặt ở giữa thanh dropdown, ta muốn di chuyển giá trị 18時 lên đỉnh của thanh cuộn thì viết một đoạn code js như sau:   var $dropdown = $(dropdownElement); var selectedIndex = $dropdown.find('.selected').data(liTagIndex); var liHeight = $dropdown.find('li').first().outerHeight(); $dropdown.scrollTop(selectedIndex*liHeight);   ...