1

因此,当单击时,我modalLink想从tdthis 内部tr而不是 other内部获取并保存数据值tr

<tr date-user-id="1NJD3A" data-user-details="{...}" class="">
    <td class="table-request-btn incoming-icon">
        <button class="modalLink" href="#modalrequest">Request Intro</button>
    </td>
    <td class="data-name request-row">
        Joe Blow
    </td>
    <td class="data-career request-row">
        Administrator
    </td>
    <td class="data-company request-row">
        Acme
    </td>
</tr>



到目前为止,我的函数抛出了一个无法实现的 Uncaught TypeError

你会如何处理这个问题?

var wireSearchTable = function() {
    $('.modalLink').unbind('click').bind('click', function () {
        var request_name = $(this).parents('tr').siblings.data('name');
        var request_title = $(this).siblings.data('career');
        var request_company = $(this).siblings.data('company');
            requestIntroModal.wireRequestIntroModal(details);

            console.log('request_name = '+request_name);
            console.log('request_title = '+request_title);
            console.log('request_company = '+request_company);
        });
    };
4

2 回答 2

1

我个人建议:

$('button.modalLink').click(function (e) {
    e.preventDefault();
    var row = $(this).closest('tr');

    // I have absolutely no idea what the following is meant to do,
    // if anything, therefore it's not in the linked demo,
    // and remains commented-out here.
    // requestIntroModal.wireRequestIntroModal(details);

    people = {
        'name': row.find('td.data-name').text(),
            'career': row.find('td.data-career').text(),
            'company': row.find('td.data-company').text()
    };
    console.log(people);
});

JS 小提琴演示

参考:

于 2013-07-10T17:58:12.777 回答
1

也许这就是你想要的?

var wireSearchTable = function() {
    $('.modalLink').unbind('click').bind('click', function () {
        var this_tr = $(this).closest('tr'),  // grab the parent <tr>
            request_name = this_tr.siblings('.some-class-name-or-id').data('name'),
            request_title = this_tr.find('.data-career').data('career'),
            request_company = this_tr.find('.data-company').data('company');

        requestIntroModal.wireRequestIntroModal(details);

        console.log('request_name = '+request_name);
        console.log('request_title = '+request_title);
        console.log('request_company = '+request_company);
    });
};
于 2013-07-10T17:58:31.400 回答