前提・実現したいこと
Rails4, CoffeeScriptで記載された下記のソースがあります。
data
は$ajaxで取得したデータです。
$('#user_lists_body').on 'ready scroll', (e) -> scrollTop = $(this).scrollTop() bottom = $(this).get(0).scrollHeight - $(this).get(0).offsetHeight offset = $('#user_lists').children().length if loadUserList == 1 && bottom - scrollTop < 600 loadUserList = 0 $.ajax url: '/line_users/user_list.json', type: "GET", datatype: 'json' data: {'offset': offset} success: (data, status) -> loadUserList = 1 if(data.length == 0) loadUserList = 0 for row in data template = $('#user_list_template > a').clone() alert(row['user']) template.attr('id', 'people-' + row['user']['id']) template.data('user_id', row['user']['id']) template.find('li').addClass('people-' + row['user']['id']) template.find('li > .name').html(userDisplay(row['user'])) template.find('li > .time').html(row['regAt']) template.find('li > .preview').html(row['latest_message']['body']) template.find('li > input').val(row['user']['id']) $('#user_lists').append(template)
dataの内容ををバインドしたいのですが下記のようなDOMを書いてもバインドされません。
%section %div %div#user_lists_body.user_list_scroll %div#user_lists %dev#user_list_template %a %ul %li %span.name %span.time %span.preview %input{type: "text"}
coffeeScirptとhamlを触るのが初めてで、jqueryも不慣れなため記法が独特過ぎて
混乱しているのですが、DOM、もしくはスクリプトをどう修正すればバインドされるでしょうか。
特にわからないのが、下記のように記載しているにも関わらずスクロールイベント発生時にしかこの処理が呼ばれないことです。画面表示時に呼ばれるようにするにはどうしたら良いでしょうか。
$('#user_lists_body').on 'ready scroll',
よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー