2013-05-02 20 views
0

嗨,我只想填充選擇或組合框。 我能夠將searchAttr同時填充爲來自JSON的任何字符串。但是當有空值時不是這樣。dojo 1.8:使用包含空值的數據庫項目填充選擇框

JSON字符串:

[{"batch":"0000001000"},{"batch":"0000"},{"batch":""},{"batch":null}] 

道場代碼:

var selBatch = new ComboBox //located at the left side of the page and it is the second select box in a row 
(
    { id:'ID_selBatch', 
     value:'', 
     searchAttr:'batch', 
     placeHolder:'Select...', 
     style:{width:'150px'}, 
    }, 'node_selBatch' 
); 

on(selTest, 'change', function(valueCard) 
{ 
    var selectedTest = this.get('displayedValue'); 
    var selBatch = registry.byId('ID_selBatch'); 
    console.debug('Connecting to gatherbatches.php ...'); 
    request.post('gatherbatches.php', 
    { data:{nameDB:registry.byId('ID_selPCBA').value, nameCard : valueCard}, 
     handleAs: "json"}).then 
     (
      function(response) 
       { 
        var memoStore2 = new Memory({data:response}); 
        selBatch.set('store', memoStore2); 
        selBatch.set('value',''); 
        console.debug('List of batches per Test is completed! Good OK! '); 
       }, 
      function(error) 
       { 
        alert("Batch's Error:"+error); 
        console.debug('Problem: Listing batches per Test in select Test is BAD!'); 
       } 
     ); 
    selBatch.startup(); 

}); 

錯誤:

TypeError: _32[this.searchAttr] is null 
      defer()        -> _WidgetBase.js (line 331) 
      _3()        -> dojo.js (line 15) 
      _f.hitch(this,fcn)();    -> _WidgetBase.js (line 331) 

請告知,雖然它可能奇怪,有NULL值的選擇框,但這些填充空值與數據庫中其他列中的數據相關,因此包含空值以便我可以應用之後的mysql腳本。或者你還有其他更好的建議嗎?

克萊門特

回答

0

您可以創建一個QueryFilteras in this jsfiddle達到你想要什麼,但它可能是簡單的有兩個數據項。您的原始模型可能有nullbatch屬性,以及您傳遞到ComboBox使用的商店的模型。

但不管怎麼說,這可以工作:

function createQueryFilter(originalQuery, filter) { 
    return function() { 
     var originalResults = originalQuery.apply(this, arguments); 
     var results = originalResults.filter(filter); 
     return QueryResults(results); 
    }; 
} 

var memoStore = new Memory({ 
    data: data 
}); 
memoStore.query = createQueryFilter(memoStore.query, function (item) { 
    console.log(item); 
    return !!item.batch; 
}); 

和虛擬數據:

function createData1() { 
    var data = []; 
    for (var i = 0; i < 10; i++) { 
     data.push({ 
      name: "" + i, 
      batch: (0 === i % 2) ? "batch" + i : null 
     }); 
    } 
    return data; 
} 

截圖。在我的示例中,奇數編號的批處理項目爲空。

enter image description here

相關問題