1

データベースから取得した本のタイトルを切り捨てて、バーコードラベルに印刷しようとしています。同じページのテーブルに表示するにはタイトル全体を表示する必要があるため、クエリから切り捨てることはできません。これが私が持っているものです:

   $.ajax({
        type: "POST",
        url: "advanceProcess.php",
        dataType: "json",
        data: ({sourceID: $('#sourceID').val(), fromDate: $('#fromDate').val(), toDate: $('#toDate').val()}),
        success: function(data){
            if(data.isbn == null ){
                $("#acctRecords").append('<tr><td>No Records Found</td></tr>');
            }else{
                //append general data
                for(var x=0;x<data.isbn.length;x++)
                {
                    $("#acctRecords").append('<tr><td id="tableSKU">'+data.tempsku[x]+
                    '</td><td id="tableISBN">'+data.isbn[x]+
                    '</td><td id="tableTitle">'+data.title[x]+
                    '</td><td id="tableOrderid">'+data.orderId[x]+
                    '</td><td id="tableQtyBought">'+data.quantity[x]+
                    '</td><td id="tableCost">'+data.cost[x]+
                    '</td><td id="tabledateCreated">'+data.dateCreated[x]+
                    '</td><td id="tableWeight">'+data.weight[x]+
                    '</td><td id="tableCheckNumber">'+data.checkNumber[x]+'</td></tr>');
                }// end of for loop
                //refreshes the tablesorter plugin
                $("#acctRecords").trigger("update");
    //Print the bar codes
    sku = data.tempsku;
    title = data.title[x];
    //console.log(JSON.stringify(data));
    title = title.substr(0,16);
    var x=0;
    for (x=0;x<title.length;x++)
    {   
        first += '$("#'+indexGlobal+'").barcode("'+sku[x]+'", "codabar",{barHeight:40, fontSize:30, output:"bmp"});';
        second += '<div class="wrapper"><img src="../images/temp.jpg" /><div id="'+indexGlobal+
        '"></div><div class="fullSKU">&nbsp &nbsp &nbsp '+sku[x]+'</div><br/><div class="title">'+title[x]+
        '</div></div><br/><div class="page-break"></div>';
        indexGlobal++;
    }           

タイトルが長すぎることを除いて、すべてが正常に機能しました。現在、次のようなエラーが発生しています。TypeError:title.substrは関数ではありません。私はこことGoogleでいくつかの調査を行いましたが、私のコードは正しいようです。何か案は?

編集:JSONの結果は次のとおりです:

"title":["Understanding and Applying Medical Anthropology","The Ethical Chemist : Professionalism and Ethics in Science","Magic, Witchcraft, and Religion: A Reader in the Anthropology of Religion","Principles of Cancer Biology","AIDS and Accusation: Haiti and the Geography of Blame","In Search of Respect: Selling Crack in El Barrio (Structural Analysis in the Social Sciences)"] 

編集2:スクリプトを更新して、ajax呼び出し全体と結果がどのように返されるかを示しました。

4

2 に答える 2

1

配列から最初のタイトルを取得するために、複数のタイトルを使用しています。

title = data.title[0];
title = title.substr(0,16);

タイトルごとにバーコードを作成する場合:

for(x=0; x<data.title.length; x++)
{
   title = data.title[x];
   title = title.substr(0,16);

   // Build barcode

}
于 2012-08-01T17:59:41.270 に答える
0
//Your object [JSON]
var obj = {"title":["Understanding and Applying Medical Anthropology","The Ethical     Chemist : Professionalism and Ethics in Science","Magic, Witchcraft, and Religion: A Reader in the Anthropology of Religion","Principles of Cancer Biology","AIDS and Accusation: Haiti and the Geography of Blame","In Search of Respect: Selling Crack in El Barrio (Structural Analysis in the Social Sciences)"]}

//Result
obj.title[0] // Understanding and Applying Medical Anthropology
于 2012-08-01T18:01:33.407 に答える