2013-08-20 2 views
1

3 일 동안 작업했지만 문제가 발생했지만 해결책을 찾을 수 없습니다 !!! 은 document.ready에서는 전 서브 오브젝트kendoGrid에서 레코드를 추가 할 수 없습니다.

var datasource = [ 
    { 
    "category": { 
     "id_category": 1, 
     "desc_category": "Beverages" 
    }, 
    "id_product": 1, 
     "desc_product": "Chai", 
     "price": "11", 
     "id_category": 1 
    }, 
    { 
    "category": { 
     "id_category": 2, 
     "desc_category": "Condiments" 
    }, 
    "id_product": 2, 
     "desc_product": "Aniseed Syrup", 
     "price": "12", 
     "id_category": 2 
} 
] 

하고 난 편집 모드 표에서 콤보 박스를 채우는

var kendoGrid = $("#grid").kendoGrid({ 

    selectable: true, 
    dataSource: datasource, 
    resizable: true, 
    toolbar: [{ 
     name: "create", 
     text: "Add Something" 
    }], 
    columns: [ 
     { field: "desc_product", title: "Description", width: 100 }, 
     { field: "price", title: "Price", width: 100 }, 
     { field: "id_product", title: "Category", width: 200, editor: categoryDropDownEditor, template: '#=category.desc_category#' }, 
     { 
      command: [{ 
       name: "destroy", 
       text: "Delete", 
       confirmation: "Are you sure?" 
      }, 
      { 
       name: "edit", 
       text: { 
       edit: "Edit", 
       update: "Update", 
       cancel: "Cancel" 
      } 
      } 
      ] 
     } 
    ], 
    width: 200, 
    height: 300, 
    editable: editable = { 
     mode: "inline", 
     confirmation: "Are you sure?" 
    } 
}); 

마침내 기능 kendogrid를 생성과 데이터 소스를 생성

function categoryDropDownEditor(container, options) { 
var ds = [ 
{   
     "id_category": 1, 
     "desc_category": "Beverages" 
}, 
{ 
    "id_category": 2, 
    "desc_category": "Condiments" 
}, 
{ 
    "id_category": 3, 
    "desc_category": "Confections" 
}, 
{ 
    "id_category": 4, 
    "desc_category": "Produce" 
}, 
{ 
    "id_category": 5, 
    "desc_category": "Sea Food" 
} 
]; 

$('<input data-text-field="desc_category" data-value-field="id_category" data-bind="value:' + options.field + '"/>"') 
    .appendTo(container) 
    .kendoComboBox({ 
     index: 0, 
     placeholder: "Select Category", 
     dataTextField: "desc_category", 
     dataValueField: "id_category", 
     dataSource: ds 
    }) 
} 

새 레코드를 추가하려고하면 오류가 발생합니다 (런타임 오류 : 범주는 정의되지 않음).

데이터 소스가 맞는지 누군가가 알 수 있습니까? 코드의 구조가 맞습니까? 어디에 문제가 있습니까?

누군가 나를 도울 수 있기를 바랍니다 !!!

답변

1

, 당신은 columns.field에 기본 값을 설정해야합니다. classe_iva 변수가 선언되지 않았기 때문에 오류가 발생합니다. 글로벌이라고 선언하십시오. 희망이 도움이됩니다.

+0

나는 같은 문제가 있지만 실제로 classe_iva 무엇이며 그것을 선언하는 방법을 얻지 못하겠습니까? 도움이 될만한 표본이 있습니까? – Gabriel

2

문제는 새로운 레코드를 만들 때 DataSourceschema.model이 없기 때문에 category이 정의되지 않았고 정의되지 않았습니다. categoryDropDownEditor 함수를 호출하기 전에 실제로 template이 인스턴스화되고 오류가 발생합니다. 현재 행의 data가 실제로 사용 category에 정의되어 있음을 확인

template: '#= data.category ? data.category.desc_category : 1 #' 

다음 template의 오류를 수정

그냥 같은 것을 할 필요가 꽤 쉽다.

하지만이 더 schema.model 정의가 없기 때문에 당신이 popup을 닫을 수 있다는 것입니다 다음 문제로 이동합니다.

당신이 정의하는 시도 할 수있는 DataSource로 : 당신이 새 레코드를 추가 할 때

var datasource = new kendo.data.DataSource({ 
    data : [ 
     { 
      "category" : { 
       "id_category" : 1, 
       "desc_category": "Beverages" 
      }, 
      "id_product" : 1, 
      "desc_product": "Chai", 
      "price"  : "11", 
      "id_category" : 1 
     }, 
     { 
      "category" : { 
       "id_category" : 2, 
       "desc_category": "Condiments" 
      }, 
      "id_product" : 2, 
      "desc_product": "Aniseed Syrup", 
      "price"  : "12", 
      "id_category" : 2 
     } 
    ], 
    schema: { 
     model: { 
      id : "id_category", 
      fields: { 
       desc_product: { type: "string" }, 
       price  : { type: "number" } 
      } 
     } 
    } 
}); 
+0

도움이 필요하십니까? :) – pasluc74669

+0

하지만 내 대답을 시도 했습니까? 너의 문제는 무엇인가? – OnaBai

+0

귀하의 제안을 사용하여 위의 전체 코드를 게시했지만 문제는 동일합니다. 새 레코드를 추가 할 때 데이터 소스가 정의되지 않았습니다. – pasluc74669

관련 문제