我有一個加載在document.ready()上的kendo數據源,並用來自JSON請求的結果填充組合框。然後,一旦用戶選擇組合框中的一個項目,我告訴有一個函數customerSelected()執行來爲該客戶加載值。我遇到的問題是我無法在頁面加載後設置另一個Kendo數據源來填充數據。如果我使用常規的Jquery ajax調用,那麼在執行Kendo模板之後數據似乎會加載並且不會填充我的數據。加載頁面後的Kendo數據源
function customerSelected(customerid) {
var customer = customerid;
var commTemplate = kendo.template(' # for (var i=0; i < data.length; i++) { # <div class="communication" contentEditable>#= data[i].fname # - #= data[i].lname # #= data[i].details #</div> # } # ');
var commData = new kendo.data.DataSource({
transport: {
read: {
url: "index.php?mode=showCustomerData",
dataType: "json"
}
}
});
$("#communications").html(commTemplate(commData));
}
$('document').ready(function() {
var customers = new kendo.data.DataSource({
transport: {
read: {
url: "index.php?mode=showCustomers",
dataType: "json"
}
}
});
$("#customerBox").kendoComboBox({
dataSource: customers,
dataTextField: "name",
dataValueField: "customer_id",
filter: "contains",
change: function(e) {
console.log(this.value());
customerSelected(this.value());
$("#customerSelected").val(this.value());
}
});
});
此處的每個數據源均會返回正確的JSON數據,這些數據與其他客戶端進行了驗證。問題在於customerSelected()函數中的kendo.data.DataSource()實際上沒有做任何事情。我嘗試了各種方法來獲得這個功能,我習慣於在純粹的JQuery世界中進行Ajax調用和附加/更新DOM。在DOM被加載後,我在這裏丟失了什麼以允許另一個DataSource?
這是有益的,但它不填充數據。我看到DataSource實際上向服務器發出了請求,Chrome網絡開發者選項卡顯示結果:[{「id」:「1」,「fname」:「Keiser」,「lname」:「Von」,「details」 :「這些都是一些細節」}]但數據不會在頁面上迭代。我能夠讓模板引擎來做迭代的數據,當我嘗試使用jquery,但數據字段沒有正確分配 – Keizer
也許我需要定義模式? console.log()報告{「options」:{「data」:[],「schema」:{},「serverSorting」:false,「serverPaging」:false,「serverFiltering」:false,「serverGrouping」 「serverAggregates」:假的, 「一批」:假的, 「運輸」:{ 「讀」:{ 「URL」: 「的index.php模式= showCustomerData」, 「數據類型」: 「JSON」}}}, 「_地圖」 :{}, 「_預取」:{}, 「_數據」:[], 「_ pristineData」:[], 「_範圍」:[], 「_視圖」:[], 「_原始」:[], 「_毀」: [], 「_基團」:[], 「_事件」:{ 「同步」:[空]}, 「運輸」:{ 「選項」:{ 「讀」:{ 「URL」?「的index.php模式= showCustomerData「,」dataType「:」json「}},」cache「:{}},」reader「:{},」_ requestInProgress「:true} – Keizer
進一步修補程序我能夠獲取數據, :function(){$(「#communications」)。html(commTemplate(this._pristine)); } – Keizer