首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FooTable是未定义的错误

FooTable是未定义的错误
EN

Stack Overflow用户
提问于 2015-10-30 16:26:15
回答 1查看 2.6K关注 0票数 0

我正在尝试构建一个fooTable,其中我的表头声明位于另一个表单上,而html行字段位于另一个表单上。这是设计,

pro

代码语言:javascript
复制
    <table class="footable table" id="L-EGY-TRG-501-00BP_fooTable" >
        <thead>
            <tr>
                    <th data-sort-initial="true" data-toggle="true">Employed by</th>
                    <th>Category</th>
                    <th data-hide="phone, tablet">Sub-Category</th>
                    <th data-hide="phone, tablet">Attendee Count</th>
            </tr>
        </thead>
      <tbody id="L-EGY-TRG-501-00BP_fooTableBody">
    </tbody>
</table>

trg-行表

代码语言:javascript
复制
<table>
    <tr id="yyy" data-losstype="fin-row" data-GUID="L-EGY-TRG-ROW-501-003H">
        <td>
            <input type="text" class="form-control" id="yyy_EmployedBy" name="yyy_EmployedBy" value=""   >
        </td>
        <td>
            <input type="text" class="form-control" id="yyy_Category" name="yyy_Category" value=""   >
        </td>
        <td>
            <input type="text" class="form-control" id="yyy_SubCategory" name="yyy_SubCategory" value=""   >
        </td>
        <td>
            <input type="text" class="form-control" id="yyy_attendeecount" name="yyy_attendeecount" value=""   >
        </td>


        <td>
            <button type="button" class="btn btn-sm btn-default btn-rounded" onClick="#" title="Add Attendee Row">
                    <i class="fa fa-plus"></i>
            </button>
            &nbsp;
            <button type="button" class="btn btn-sm btn-default btn-rounded removeRowLink" onClick="#" title="Remove Attendee Row">
                    <i class="fa fa-minus"></i>
            </button>
        </td>

    </tr>
</table>

这就是我使用JQuery的方法,

代码语言:javascript
复制
$(document).ready(function(){
        guid="xxxxx"
        prepTable("/pro?openform,guid); //
});
function prepTable(surl,guid){
            $.get( surl, function( data ) {               

        var footable = $(data).find('.footable').footable();

        guid="xxxxx";                     
        buildFooTable(guid,"/trg-row?openform");

            });
}

 funtion buildFooTabl(containerID,surl) {
        $.get( surl, function( data ) {  
            var $row = $(data).find('#yyy');
            var footable = $('#' + containerID + '_fooTable').data('footable');
            var rowid = $row.attr('data-GUID');
            $row.find('[id*=yyy]').each(function() {
                   var id = this.id || "";
                   this.id = id.replace('yyy', rowid)
              });
            $row.find('[name*=yyy]').each(function() {
                var nm = this.name || "";
                    this.name = nm.replace('yyy', rowid)
             });

         $row.attr('id',rowid);
             footable.appendRow($row);
        });

但是在这一行中得到的错误"TypeError: footable是未定义的“,但是fooTable id是正确的。

代码语言:javascript
复制
var footable = $('#' + containerID + '_fooTable').data('footable');
EN

回答 1

Stack Overflow用户

发布于 2015-10-30 16:50:30

您所得到的错误在这条线上:

代码语言:javascript
复制
var footable = $('#' + containerID + '_fooTable').data('footable');

问题是在html中没有像"data-footable“这样的属性。

jQuery方法.data('parm')提取数据-parm属性的值。这个参数是无关的。如果你有这样的div:

代码语言:javascript
复制
<div id="mydiv" data-mytext="This is my text"></div>

你这样做:

代码语言:javascript
复制
var mytext = $('#mydiv').data('mytext')
alert(mytext);

警报会说:“这是我的短信”。因为.data('mytext')函数已经提取了data-mytext属性的值。

那么,您要加载到var footable中的是什么呢?如果您试图获取对表的引用,并且拥有正确的containerID,那么您只需要

代码语言:javascript
复制
var footable = $('#' + containerID + '_fooTable');
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33440637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档