2017-03-07 112 views
0

如何檢查是由ExtJs(6)添加和生成的模型的「id」字段還是實際存在於後端?檢查是否生成ExtJs模型ID

我使用網格和JSON商店獲取的各種數據和生成列電網動態如下:

 store.load(function(records, operation, success) { 
      if(success) 
      { 
      //console.log('Store loaded records',records,store); 
      if(records.length) 
      { 
       var columns = _.map(records[0].data,function(value, key){ 
       return {text:key,dataIndex:key}; 
       }); 
       me.reconfigure(store,columns); 
      }else{ 
       me.reconfigure(store,[{text:"no records",dataIndex:"no records"}]); 
      } 
      } 
      else 
      console.log('Store NOT loaded'); 
     }); 

而且我不希望顯示自動生成的字段「ID」,但仍需要顯示它,如果它是'真實的'。

我試圖用自定義idProperty定義商店的模型屬性 - 但它看起來在這種情況下不起作用, 隻影響它已經消失的文本前綴「extModelxxx-」從生成的id值,但它仍然有我在idProperty指定的「ID」的名字,而不是一個名字:

{ 
     reference:"dataDisplay", 
     xtype:"grid", 
     store:{ 
     type:"json", 
     proxy:{ 
      type: 'ajax', 
      url: '',//will be set dynamically 
      reader: { 
      type: 'json', 
      rootProperty: 'value' 
      }, 
     }, 
     model: Ext.create("Ext.data.Model",{ 
      //fields:["extJsAutoId"],//no effect 
      idProperty:"extJsAutoId",//null,//null does not work too 
     }), 
     }, 
     columns: [], 
     listeners:{ ....... 

我只看到現在的方式是自己加載JSON,然後用數組存儲。

我創建搗鼓這個問題: https://fiddle.sencha.com/#view/editor&fiddle/1rj5

,當你在下面的截圖看到 - 「幻影」屬性始終是假的,所以它不能幫助這裏:

enter image description here

回答

0

你可以檢查記錄的phantom屬性,這意味着它沒有被服務器分配一個id。

您可以使用此列渲染器實現:

{ 
    text: 'ID', 
    dataIndex: 'id', 
    renderer: function(v, meta, rec) { 
     return rec.phantom ? '' : v; 
    } 

} 
+0

我試圖檢查幻影道具,但它總是假的,不管是生成的「ID」字段,或者從服務器接收。 –

+0

看這裏請: https://fiddle.sencha.com/#view/editor&fiddle/1rj5 正如你在控制檯中看到的兩種情況下phantom == false –

+0

哦,他們來自沒有ID的遠程源? –