开发者

Creating a DOM for Textarea from SQL queries table result

I got the DOM object that creates table and I want a new function /DOM that create a Textarea from table result with a column name AsText(Geometry) (i.e. fieldName[i] = "AsText(Geometry)). This is SQLite3 query.

Here is the DOM that creates table html

function displayWKTqueryVCF(bcoResults, parameters){
    //debug('displaying scores');
    /*
     * the data array has multiple results from multiple BCF calls.
     * the first one has the data needed here.
     */
    var aResult = bcoResults[0];
    if(aResult.errorMessage != 'not an error'){
        handleError('queryError',[aResult.errorMessage]);
        return;
    }
    var fieldNames = aResult.fieldNames;
    var records = aResult.data;
    var numFields = fieldNames.length;
    var numRecords = records.length;
    var container = document.getElementById('queryResults');
    containe开发者_如何学Gor.innerHTML = '';
    var table = document.createElement('table');
    container.appendChild(table);


    var headerRow = document.createElement('tr');
    table.appendChild(headerRow);
    for(var i = 0; i < numFields; i++){
        var header = document.createElement('th');
        header.innerText = fieldNames[i];
        headerRow.appendChild(header);
    }

    for(var i = 0; i < numRecords; i++){
        var tableRow =  document.createElement('tr');
        table.appendChild(tableRow);


        for(var j = 0; j < numFields; j++){
            var tableData = document.createElement('td');           

            tableRow.appendChild(tableData);
            tableData.innerText = records[i][j];
        }
    }

}

Output:

<table>
    <tr>
         <th>name</th>
         <th>city</th>
         <th>AsText(Geometry))</th>
    </tr>
    <tr>
         <td>Andres Street</td>
         <td>Nowhere City</td>
         <td>LINESTRING(7.120068 43.583917,7.120154 43.583652,7.120385 
          43.582716,7.12039 43.582568,7.120712 43.581511,7.120873 43.580718)</td>
    </tr>
</table>

I wanted a new function, that is Textarea, not table. One of the problem is how to store 2D data into textrarea (i.e. records[i][j];). Append?

~~~~~~~~~~~~~~

function displayAsTextGeometryVCF(bcoResults, parameters){

   var aResult = bcoResults[0];
   if(aResult.errorMessage != 'not an error'){
       handleError('queryError',[aResult.errorMessage]);
       return;
   }
   var fieldNames = aResult.fieldNames;
   var records = aResult.data;
   var numFields = fieldNames.length;
   var numRecords = records.length;
   // var container = document.getElementById('queryAsTextGeometry');

   var oTextarea = document.getElementById('wktResult');
   oTextarea.innerHTML = '';

   var g = 0;

   for(var i = 0; i < numFields; i++){

       if fieldNames[i] = "AsText(Geometry)" then
        var g = i;
   }

   for(var g ){

       for(var j = 0; j < numFields; j++){

            document.getElementById('wktResults').value = records[g][j];
           //tableData.innerText = records[g][j];
       }
   }

}

Wanted Desired Output:

<textarea>LINESTRING(7.120068 43.583917,7.120154 43.583652,7.120385 
      43.582716,7.12039 43.582568,7.120712 43.581511,7.120873 43.580718)</textrea>

How can this addtext corporate to above code.

function addtxt(input) {
var obj=document.getElementById(input)
var txt=document.createTextNode("blah blah")
obj.appendChild(txt)

The textarea and button:

    <a href="#wktInput"  data-inline="true" data-role="button">WKT Result</a>

      <textarea cols="160" rows="10" style="color: green; background-color: black" name="wktResult" >WKT Results</textarea>


It is hard to tell what part of this you are having trouble with. I'm supposing that you are having trouble getting your displayAsTextGeometryVCF() function to work. Here is a rewritten version. Please try it:

function displayAsTextGeometryVCF(bcoResults) {
    var aResult = bcoResults[0];
    if (aResult.errorMessage != 'not an error') {
        handleError('queryError', [aResult.errorMessage]);
        return;
    }

    var fieldNames = aResult.fieldNames,
        records = aResult.data,
        container = document.getElementById('queryResults');
    container.innerHTML = '';

    var theField = 0;
    for (var i = 0, ii = fieldNames.length; i < ii; i++) {
        if (fieldNames[i] == 'AsText(Geometry)') {
            theField = i;
            break;
        }
    }

    for (var i = 0, ii = records.length; i < ii; i++) {
        var t = document.createElement('textarea');
        t.innerText = records[i][theField];
        container.appendChild(t);
    }

}

For this data:

displayAsTextGeometryVCF([{
    errorMessage: 'not an error',
    fieldNames: ['dummy', 'AsText(Geometry)'],
    data: [
        ['one','yes'],
        ['no','yes']
    ]
}]);

The output is:

<div id="queryResults"><textarea>yes</textarea><textarea>yes</textarea></div>

Is that what you wanted?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜