2011-04-27 5 views
4

내 페이지에 ItemFileWriteStore이 있습니다. 내 DataGrid에있는 행을 클릭하면 그 행의 ID를 얻을 수 있지만 그 다음에 해당 ID를 사용하여 fetchItemByIdentity을 시도하면 항상 null을 반환합니다. 왜이게 될 수 있니?fetchItemByIdentity()가 예상대로 작동하지 않습니다.

Dojo 1.5를 사용하고 있습니다.

function getRemoveFormatter(id) { 
    return '<a href="#" onclick="deleteItem(' + id + ');return false;"><img src="/images/icons/delete.png" /></a>'; 
} 

function deleteItem(id) { 
    console.log(id); 
    window.grid.store.fetchItemByIdentity({ 
    identity: id, 
    onItem: function(item, request) { console.log(item); } 
    }); 
    //window.grid.store.deleteItem(id); 
} 

dojo.ready(function() { 
    var store = new dojo.data.ItemFileWriteStore({data:{items:[]}}); 
    window.grid = new dojox.grid.DataGrid({ 
    store: store, 
    structure: [ 
     { name: "id", field: "id", width: "50px" }, 
     { name: "Stylist", field: "stylist", width: "100px" }, 
     { name: "Service", field: "service", width: "200px" }, 
     { name: "Length", field: "length", width: "50px" }, 
     { name: "Remove", field: "remove", width: "30px", formatter: getRemoveFormatter } 
    ], 
    identifier: "id", 
    label: "id"}); 
    dojo.byId("services_grid").appendChild(grid.domNode); 
    grid.startup(); 
    observeAppointmentServiceAddClick(window.grid); 
    getAppointmentItems(); 
}); 

답변

2

스토어와 그리드를 선언하는 방식을 약간 변경해보십시오. 식별자 W 레이블 등록 정보는 항목 옆에있는 상점의 데이터 섹션에 속합니다.

var store = new dojo.data.ItemFileWriteStore({data:{ 
    items:[], 
    identifier: "id", 
    label: "id"}}); 

window.grid = new dojox.grid.DataGrid({ 
store: store, 
structure: [ 
    { name: "id", field: "id", width: "50px" }, 
    { name: "Stylist", field: "stylist", width: "100px" }, 
    { name: "Service", field: "service", width: "200px" }, 
    { name: "Length", field: "length", width: "50px" }, 
    { name: "Remove", field: "remove", width: "30px", formatter: getRemoveFormatter } 
]}); 
+0

그것을 않았다! 고맙습니다!!!!! –

+0

위대한! 도움이 된 것을 기쁘게 생각합니다! –

1

다음은 jsfiddle에서 간단한 코드와 대답입니다.

http://jsfiddle.net/martlark/UkKXW/1/

<html> 
    <head><!--dojo stuff--></head> 
    <body> 
     <div id='store'></div> 
     <div id='log'></div> 
    </body> 
</html> 


dojo.require("dojo.data.ItemFileWriteStore"); 
var store = null; 

function getItem(id) { 
store.fetchItemByIdentity({ 
    identity: id, 
    onItem: function (item, request) { 
     var v = store.getValue(item, 'value'); 
     dojo.byId('log').innerHTML = 'getItem(' + id + ') =' + v; 
    } 
}); 
} 

dojo.ready(function() { 
var items = []; 

for (var p = 0; p < 5; p++) { 
    items.push({ 
     id: p, 
     value: 'v ' + p 
    }); 
} 

store = new dojo.data.ItemFileWriteStore({ 
    data: { 
     identifier: 'id', 
     items: items 
    } 
}); 

var gotList = function (items, request) { 
    var itemsList = "<ul>"; 
    dojo.forEach(items, function (i) { 
     itemsList += '<li> id:' + p + ' = ' + store.getValue(i, 
      "value") + "</li>"; 
    }); 
    itemsList += '</ul>'; 
    dojo.byId('store').innerHTML = itemsList; 
} 
var gotError = function (error, request) { 
    alert("The request to the store failed. " + error); 
} 
// Invoke the search 
store.fetch({ 
    onComplete: gotList, 
    onError: gotError 
}); 
getItem('2'); 
}); 
관련 문제