2016-05-17 89 views
-1

我在一開始就得到這個錯誤。不知道如何解決。我也得到了期望的任務或函數調用,而是看到了一個表達式。更何況預期的標識符,而是看到了「VAR」預期的標識符,而是看到了「<」

<script> 
var interactiveSearch = {}; 
(function() { 
    interactiveSearch.common = { 
    init: function() { 
     interactiveSearch.common.setupDataTableDefaults(); 
     $.ajaxSetup({ 
     cache: false 
     }); 
    }, 
    setupDataTableDefaults: function() { 
     $.extend($.fn.dataTable.defaults, { 
     "sDom": "<'table-header-controls'<'row'<l><f>>r><i>t<'table-footer-controls'<'row'<'span12'p><'span12'i>>>", 
     "sPaginationType": "bootstrap", 
     "bJQueryUI": false, 
     "bProcessing": false, 
     "bServerSide": true, 
     "fnServerData": interactiveSearch.common.getTableData 
     }); 
    }, 
    getTableData: function(sSource, aoData, fnCallback) { 
     var data = new Array(); 
     var columnCount = _.find(aoData, function(o) { 
     return o.name == 'iColumns'; 
     }).value; 
     var echo = _.find(aoData, function(o) { 
     return o.name == 'sEcho'; 
     }).value; 
     var skip = _.find(aoData, function(o) { 
     return o.name == 'iDisplayStart'; 
     }).value; 
     var take = _.find(aoData, function(o) { 
     return o.name == 'iDisplayLength'; 
     }).value; 
     var search = _.find(aoData, function(o) { 
     return o.name == 'sSearch'; 
     }).value; 
     var sortCols = _.filter(aoData, function(o) { 
     return o.name.indexOf('iSortCol_') == 0; 
     }); 
     var sortDirs = _.filter(aoData, function(o) { 
     return o.name.indexOf('sSortDir_') == 0; 
     }); 
     var searches = _.filter(aoData, function(o) { 
     return o.name.indexOf('sSearch_') == 0; 
     }); 
     data.push({ 
     "name": "TableEcho", 
     "value": echo 
     }); 
     data.push({ 
     "name": "Skip", 
     "value": skip 
     }); 
     data.push({ 
     "name": "Take", 
     "value": take 
     }); 
     data.push({ 
     "name": "AllSearch", 
     "value": search 
     }); 
     var actual = 0; 
     _.each(sortCols, function(columnSort, sortIndex) { 
     var columnIndex = columnSort.value; 
     var columnSearch = searches[columnIndex].value; 
     var sortDir = sortDirs[sortIndex].value; 
     data.push({ 
      "name": "Columns[" + actual + "].ColumnIndex", 
      "value": columnIndex 
     }); 
     data.push({ 
      "name": "Columns[" + actual + "].SortDirection", 
      "value": sortDir 
     }); 
     if (columnSearch != '') { 
      data.push({ 
      "name": "Columns[" + actual + "].SearchTerm", 
      "value": columnSearch 
      }); 
     } 
     actual++; 
     }); 
     for (var i = 0; i < columnCount; i++) { 
     var searchTerm = searches[i].value; 
     if (searchTerm == '') { 
      continue; 
     } 
     data.push({ 
      "name": "Columns[" + actual + "].ColumnIndex", 
      "value": i 
     }); 
     data.push({ 
      "name": "Columns[" + actual + "].SearchTerm", 
      "value": searchTerm 
     }); 
     actual++; 
     } 
     $.post(sSource, data) 
     .success(fnCallback); 
    } 
    }; 
})(); 
$(function() { 
    interactiveSearch.common.init(); 
}); 
(function() { 
    var product = interactiveSearch.product = {}; 
    product.init = function() { 
    product.initDataTable(); 
    product.bindEvents(); 
    }; 

    function convertFullRowToDataObject(fullRow) { 
    return { 
     Id: fullRow[0], 
     ProductName: fullRow[1], 
     Synonym: fullRow[2], 
     Acronym: fullRow[3], 
     CasNo: fullRow[4], 
     EinecsNo: fullRow[5], 
     Formula: fullRow[6], 
     MolecularWeight: fullRow[7], 
     Status: fullRow[8], 
     MeltingPoint: fullRow[9], 
     BoilingPoint: fullRow[10], 
     HasDoc: fullRow[11] !== '', 
     RelatedDocPath: product.baseUrl + fullRow[11], 
     HasDImage: fullRow[12] !== '', 
     ImagePath: product.baseUrl + fullRow[12] 
    }; 
    } 
    product.initDataTable = function() { 
    product.productTable = $("#product-table").dataTable({ 
     aaSorting: [ 
     [1, "asc"] 
     ], 
     iDisplayLength: 15, 
     bServerSide: true, 
     bDestroy: true, 
     sAjaxSource: interactiveSearch.product.listUrl, 
     fnRowCallback: function(nRow, aData) { 
     $(nRow).data('rowInfo', convertFullRowToDataObject(aData)); 
     }, 
     aoColumns: [{ 
     sType: "string", 
     sClass: "dtAlignLeft", 
     mData: 1 
     }] 
    }); 
    }; 
    product.bindEvents = function() { 
    _.templateSettings = { 
     interpolate: /\{\{(.+?)\}\}/g, 
     evaluate: /\{\[([\s\S]+?)\]\}/g 
    }; 
    var templateText = $('#productDetailTemplate').html(), 
     compiledTemplate = _.template(templateText); 
    $(document).on('click', '#product-table tr', function(e) { 
     var el = $(this); 
     var rowData = el.data('rowInfo'); 
     var html = compiledTemplate(rowData); 
     $('#productDetailContainer').empty().html(html); 
     $('#product-table tr').removeClass('active'); 
     el.addClass('active'); 
    }); 
    $('#searchClone').on('keyup', function(e) { 
     var el = $(this); 
     var mimicEl = $('#product-table_filter input'); 
     mimicEl.val(el.val()).trigger('keyup'); 
    }) 
    $('.btn-reset-filter').on('click', function() { 
     $('#searchClone').val('').trigger('keyup'); 
    }); 
    }; 
})(); 
$(document).ready(function() { 
    interactiveSearch.product.listUrl = '/pa/Product/ListItems'; 
    interactiveSearch.product.baseUrl = '/pa/'; 
    interactiveSearch.product.init(); 
}); 
</script> 
+2

是這一切的一個'.js'文件裏的? –

+0

你在哪一行發現錯誤? –

+1

如果這是在'.js'文件,你不應該有'周圍的代碼。這隻有在將Javascript嵌入到HTML文件中時纔會使用。 – Barmar

回答

1

在.js文件,你不必把<script>,你可以只寫你的代碼。

<script>是HTML文件時,你必須在頁面中間插入腳本。

所以,你必須在你要刪除的文件<script></script>

+1

我不知道這是怎麼回答的問題,因爲用戶@ gdeleon101自己[上述評論]回答:(http://stackoverflow.com/questions/37285211/expected-an-identifier-and-instead-saw# comment62095701_37285211)。 '此代碼是從HTML頁面內部獲取的。它不是一個獨立的.js文件。客戶端出錯了,我試圖弄清楚爲什麼 – fWd82