2014-07-16 3 views
0

와 센차 터치에서 WebSQL을 사용할 수 있습니다 어떻게 이런 일이 내 모델 :내가 고유 한 ID

Ext.define('myApp.model.Category', { 
extend: 'Ext.data.Model', 

requires: [ 
    'Ext.data.Field' 
], 

config: { 
    fields: [ 
     { 
      name: 'id', 
      type: 'int' 
     }, 
     { 
      name: 'slug', 
      type:'string' 
     }, 
     { 
      name: 'title', 
      type:'string' 
     }, 
     { 
      name: 'post_count', 
      type:'int' 
     } 
    ], 
}}); 

이 내 가게 :

지금
Ext.define('myApp.store.LocalCate',{ 
extend: 'Ext.data.Store', 

requires: [ 
    'Ext.data.proxy.Sql' 
], 

config: { 
    autoLoad:false, 
    model:'myApp.model.Category', 
    storeId:'LocalCate', 
    proxy:{ 
     type: 'sql', 
     database: 'myApp', 
     table: 'Category' 
    }, 
} 
}); 

문제가되는 : 내가 store.add({id:123,slug:'123',title:'123',post_count:123});를 사용 또는 store.add(Ext.create('myApp.model.Category'{id:123,slug:'123',title:'123',post_count:123}); 둘 다 작동하지 않습니다. '123 ID'만 그것을 밖으로 작동하고 내가 store.sync()을 할 때 WebSql 데이터베이스 '아이디'없이 데이터를 표시 데이터

{slug:'123',title:'123',post_count:123} 

를 추가 내가를 삭제할 때 나타납니다. id를 'cate_id'와 같은 다른 것으로 변경하면 작동한다는 것을 알고 있습니다. 그러나 idproperty로이 'id'를 원하며 그 이름을 변경하고 싶지 않습니다. 어떻게해야합니까? sencha touch에서 websql을 어떻게 사용합니까? LocalStorage에서도 같은 문제가 발생합니다.

답변

0

나 혼자 대답 해주세요.

// If it does not have an id in the data at this point, we use the one generated by the id strategy. 
    // This means that we will treat this record as a phantom record from now on 
    id = me.data[idProperty]; 
    if(!id && id !==0){ 
     me.data[idProperty]= me.internalId = me.id; 
     me.phantom =true; 

을 만들 때 모델이 작업을 수행하고 난 ID로 모델을 만든 경우,이 팬텀은 데이터베이스에 데이터가있는 엽차에게 그 거짓의 난) (동기화 할 때, 그것은되지 않도록 데이터베이스에 푸시됩니다.

팬텀 = true로 모델을 만든 경우에만 데이터베이스에 동기화() 할 수 있습니다.

getNewRecords:function(){ 
    returnthis.data.filterBy(function(item){ 
     // only want phantom records that are valid 
     return item.phantom ===true&& item.isValid(); 
    }).items; 
}, 
: 여기

는 addrecords 코드입니다