2014-11-03 40 views
0

我有KenfoUI網格的問題。從服務器端我送JSON數據:KendoUI - 網格 - 模板沒有獲取數據

{ 
"data": [{ 
    "process": { 
     "id": "myProcess2:1:1206", 
      "description": null, 
      "name": "My process 2", 
      "version": 1 
    }, 
     "id": 42066, 
     "description": "unisono-rest-evenem", 
     "type": { 
     "id": 2, 
      "translation": "Faktura sprzedażowa", 
      "name": "salesInvoice" 
    }, 
     "triger": { 
     "id": 42048, 
      "name": "Document recognized trigger", 
      "code": "ocrEndTrigger", 
      "type": "DOCUMENT_RECOGNIZED" 
    } 
}, { 
    "process": { 
     "id": "myProcess2:1:1206", 
      "description": null, 
      "name": "My process 2", 
      "version": 1 
    }, 
     "id": 42067, 
     "description": "6756757", 
     "type": { 
     "id": 5, 
      "translation": "Słownik stawek VAT", 
      "name": "dictVatRates" 
    }, 
     "triger": { 
     "id": 42048, 
      "name": "Document recognized trigger", 
      "code": "ocrEndTrigger", 
      "type": "DOCUMENT_RECOGNIZED" 
    } 
}, { 
    "process": { 
     "id": "myProcess2:1:1206", 
      "description": null, 
      "name": "My process 2", 
      "version": 1 
    }, 
     "id": 42068, 
     "description": "56546546", 
     "type": { 
     "id": 1, 
      "translation": "Faktura", 
      "name": "invoice" 
    }, 
     "triger": { 
     "id": 42047, 
      "name": "New document trigger", 
      "code": "createDocument", 
      "type": "CREATE_DOCUMENT" 
    } 
}, { 
    "process": { 
     "id": "myProcess2:1:1206", 
      "description": null, 
      "name": "My process 2", 
      "version": 1 
    }, 
     "id": 42069, 
     "description": "swswsws", 
     "type": { 
     "id": 5, 
      "translation": "Słownik stawek VAT", 
      "name": "dictVatRates" 
    }, 
     "triger": { 
     "id": 42047, 
      "name": "New document trigger", 
      "code": "createDocument", 
      "type": "CREATE_DOCUMENT" 
    } 
}], 
    "total": 4 
} 

,我在網格中定義的列,如:

columns: [{ 
    field: "process", 
    title: "Nazwa procesu", 
    editor: staticEditors.processEditor, 
     "template": function (data) { 
     if (data.process != null && data.process != undefined) { 
      return "<span class='gridText' title='" + data.process.name + "'>" + data.process.name + "</span>" 
     } else { 
      return "<span></span>" 
     } 
    } 
}, { 
    field: "type", 
    title: "Typ dokumentu", 
    editor: $scope.typeEditor, 
     "template": function (data) { 
     if (data.type != null && data.type != undefined) { 
      return "<span class='gridText' title='" + data.type.translation + "'>" + data.type.translation + "</span>" 
     } else { 
      return "<span></span>" 
     } 
    } 
}, { 
    field: "triger", 
    title: "Wyzwalacz", 
    editor: staticEditors.triggerEditor, 
     "template": function (data) { 
     if (data.triger != null && data.triger != undefined) { 
      return "<span class='gridText' title='" + data.triger.name + "'>" + data.triger.name + "</span>" 
     } else { 
      return "<span></span>" 
     } 
    } 
}, { 
    field: "description", 
    title: "Description", 
     "template": function (data) { 
     if (data.description != null && data.description != undefined) { 
      return "<span class='gridText' title='" + data.description + "'>" + data.description + "</span>" 
     } else { 
      return "<span></span>" 
     } 
    } 
} 

有模板功能的問題,因爲數據對象不具有的所有數據。我注意到嵌套數據有問題(字段類型,觸發器,進程有null或字符串(「[object Object]」)值。)

我該如何解決這個問題?

+0

似乎工作正常,如果我複製/粘貼您的列和數據:http://dojo.telerik.com/EKuLi – CodingWithSpike 2014-11-03 12:34:51

回答

-1

模板是不是在列字符串,

嘗試這樣,

{ 
    field: "triger", 
    title: "Wyzwalacz", 
    editor: staticEditors.triggerEditor, 
    template: function (data) { 
     if (data.triger != null && data.triger != undefined) { 
      return "<span class='gridText' title='" + data.triger.name + "'>" + data.triger.name + "</span>" 
    } else { 
     return "<span></span>" 
    } 
} 

刪除"template"併爲此template我認爲解決您的問題。

+0

它dosn't幫助。我認爲這兩種可能性沒有區別。問題是,模板函數正在工作,整個數據從服務器(我在schema.parse函數中檢查它),但在數據對象(在模板函數)應用程序中看不到嵌套的對象。 – lukisp 2014-11-03 11:32:27

+0

'模板'和''模板「'在JavaScript中是一樣的。房產名稱周圍的引號將沒有區別。 – CodingWithSpike 2014-11-03 12:28:30

0

我發現這個問題。 我將schema.model.field定義爲numer(字符串)。當我刪除它時,一切正常。