2012-07-29 3 views
2

Im new to YUI3; 10 초마다 데이터 소스를 폴링하여 데이터 테이블을 새로 고칩니다. 그러나 아래의 코드와 함께 ... '표시 할 데이터'코드의 많은 양에 대한 ... 죄송합니다 ...YUI3 - DataTable 데이터 소스 폴링

YUI().use("datatable", "datasource-get", "datasource-jsonschema", "datatable-datasource", "datasource-polling", "datasource-function", function (Y) { 

var url = "http://query.yahooapis.com/v1/public/yql?format=json" + 
       "&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys", 
    query = "&q=" + encodeURIComponent(
      'select * from local.search ' + 
      'where zip = "94089" and query = "pizza"'), 
    dataSource, 
    table; 

dataSource = new Y.DataSource.Get({ source: url }); 

dataSource.plug(Y.Plugin.DataSourceJSONSchema, { 
    schema: { 
     resultListLocator: "query.results.Result", 
     resultFields: [ 
      "Title", 
      "Phone", 
      { 
       key: "Rating", 
       locator: "Rating.AverageRating", 
       parser: function (val) { 
        // YQL is returning "NaN" for unrated restaurants 
        return isNaN(val) ? -1 : +val; 
       } 
      } 
     ] 
    } 
}); 

intervalId = dataSource.setInterval(10000, { 
    request : query, 
    callback: { 
     success: function (e) { 
      table.datasource.load(e.response); 
     }, 
     failure: function (e) { 

     } 
    } 
}); 

table = new Y.DataTable({ 
    columns: [ 
     "Title", 
     "Phone", 
     { 
      key: "Rating", 
      formatter: function (o) { 
       if (o.value === -1) { 
        o.value = '(none)'; 
       } 
      } 
     } 
    ], 
    summary: "Pizza places near 98089", 
    caption: "Table with JSON data from YQL" 
}); 

table.plug(Y.Plugin.DataTableDataSource, { datasource: dataSource }); 

// This line works (but it doesnt poll) 
//table.datasource.load({ request: query }); 

table.render("#pizza"); 
}); 

I는 확실하지 않다 라인이 없다 말한다

success: function (e) { 
      table.datasource.load(e.response); 
     }, 

답변