我的页面上有一个 ItemFileWriteStore。当我单击 DataGrid 中的任何行时,我可以获得该行的 id,但是当我尝试使用该 id 执行 fetchItemByIdentity 时,它​​总是返回 null 。知道为什么会这样吗?

我正在使用 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();
});

最佳答案

尝试在声明商店和网格的方式上做一些小的改变。标识符和标签属性属于商店旁边商品的数据部分。

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 }
]});

关于javascript - fetchItemByIdentity() 没有按预期工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5811931/

10-09 22:04