문제

편집기에서 선택한 항목을 제거해야합니다. 먼저 상점에로드되고 사용자는이 그리드에 빈 행을 추가하거나 삭제하여 편집 할 수 있습니다. 문제는 상점에서로드 된 초기 레코드를 제거하는 것이 아닙니다. 추가 행을 추가하고 편집 한 다음 제거 할 때 문제가 발생합니다 (사용자는 결국이 행이 필요하지 않다고 결정할 수 있습니다).

store.getModifiedRecords를 사용하여 변경 사항을 저장하고 싶을 때 여전히 삭제 된 행을보고 처리합니다. 버튼 제거 버튼은 다음과 같습니다.

442             
443                 text:'Remove',
444                 tooltip:'Remove attribute',
445                 iconCls:'silk-table_delete',
446                 handler: function() {
447                     var selectedItem = attributeEditor.getSelectionModel().getSelected();
448 
449                     // Check if we have selected item
450                     if (selectedItem) {
451                         // Get selected item value
452                         var attribute = selectedItem.get('Name');
453 
454                         // Remove selected
455                         attributeStore.remove(selectedItem);
456 
457                         // Add to our removed attributes hash
458                         if (id) {
459                             RemovedAttributes.push(attribute);
460                         }
461                     } else {
462                         wispUserFormWindow.getEl().mask();
463 
464                         // Display error
465                         Ext.Msg.show({
466                             title: "Nothing selected",
467                             msg: "No attribute selected",
468                             icon: Ext.MessageBox.ERROR,
469                             buttons: Ext.Msg.CANCEL,
470                             modal: false,
471                             fn: function() {
472                                 wispUserFormWindow.getEl().unmask();
473                             }
474                         });
475                     }
476                 }
477             }
도움이 되었습니까?

해결책

이것이 Store.getModifiedRecords ()가 작동하는 방식입니다. 수정 된 레코드 레코드는 매장 객체에서 수정 된 배열에 저장됩니다. 상점에서 품목을 제거하면 기본적으로 제거되지 않습니다.

다음은 상점에서 실제 remove ()입니다

remove : function(record){
    var index = this.data.indexOf(record);
    this.data.removeAt(index);
    if(this.pruneModifiedRecords){
        this.modified.remove(record);
    }
    if(this.snapshot){
        this.snapshot.remove(record);
    }
    this.fireEvent("remove", this, record, index);
}

이는 PrunEmodifiedRecords 옵션 값을 true로 지정하는 경우에만 항목이 수정 된 목록에서 제거되었음을 의미합니다. 이 값은 상점 API에 언급 된대로 기본적으로 False입니다.

새로 추가 된 항목을 수정 된 목록에서 제거하려면 상점을 만들 때 prunemodifiededrecords의 값을 true로 설정해야합니다.

var stote = new Ext.data.SimpleStore({
    fields: [],
    data: [],
    pruneModifiedRecords: true
})

다른 팁

store.load(); 
//remove function will delete specific record.
store.remove(store.findRecord("item_id","1"));
store.sync();

다음 링크는 매장을 다루는 방법을 쉽게 도울 수 있다고 생각합니다.

http://www.aswedo.net/sencha-touch/sencha-touch-adding-records-leading-data-and-deleting-records-to-store/

내 머리 꼭대기에서, 나는 당신의 코드가 왜 그런 식으로 작동하는지 알 수 없습니다. Firebug를 사용하여 중단 점을 설정하고 프로세스를 진행 했습니까?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top