簡體   English   中英

sencha touch將已刪除的列表行添加到其他列表索引

[英]sencha touch add row of list that has been removed to different index of list

我真的需要一些想法。 基本上,我正在通過單擊按鈕對列表進行排序。 如果我單擊向上按鈕,列表將上升,所選列表的索引將減少一。 當我單擊向下按鈕時,列表將下降,所選列表的索引將增加一。 我使用的方法是暫時刪除所選列表,然后根據用戶將列表插入到其他索引中。 我已經解決了刪除部分,但我不知道插入部分。 請幫忙。

這些是刪除所選列表的代碼。

var removeSelectedItems = Ext.getCmp('SearchRefSlipMain_List')。getSelection()[0]; Ext.getCmp('SearchRefSlipMain_List')。getStore()。remove(removeSelectedItems);

剩下的只是根據用戶將我已刪除的列表行插入到另一行(不同索引)。

通常,您不更改列表,而是填充列表的商店。 如果這樣做沒有幫助,您可以在這里設置小提琴嗎:

https://fiddle.sencha.com/#view/editor

(只需保存它,然后將鏈接添加到問題中的小提琴即可)

我更改了您的答案,其結果應該相同,但是速度更快:

function RowDown() {
    var direction = 1,   // 1 or -1
        treatmentDetail = Ext.getCmp('Settings_SetTreatmentList_TreatmentDetail_List'),
     // or use reference
     // treatmentDetail = this.lookup('Settings_SetTreatmentList_TreatmentDetail_List'),
        record = treatmentDetail.getSelection()[0],   //list id
        store, index;

    if (!record) {
        return;
    }

    store = treatmentDetail.getStore(),
    index = store.indexOf(record);


    index = index + (1 * direction);

    if (index >= store.getCount() || index < 0) {
        return
    }

    store.remove(record);
    store.insert(index, record);
}

按鈕:

        {
          xtype: 'button',
          iconCls: 'arrow_down',
          handler: function () {
               RowDown();

             }
         }

這是功能:

function RowDown(){

var direction = 1   // 1 or -1    
var record = Ext.getCmp('Settings_SetTreatmentList_TreatmentDetail_List').getSelection()[0];   //list id


if (!record) {
    return;
}
var index = Ext.getCmp('Settings_SetTreatmentList_TreatmentDetail_List').getStore().indexOf(record);


if (direction < 0) {
    index--;
    if (index < 0) {
        return;
    }
} else {
    index++;
    if (index >= Ext.getCmp('Settings_SetTreatmentList_TreatmentDetail_List').getStore().getCount()) {

        return;
    }
}

Ext.getCmp('Settings_SetTreatmentList_TreatmentDetail_List').getStore().remove(record);
Ext.getCmp('Settings_SetTreatmentList_TreatmentDetail_List').getStore().insert(index, record);

 }

***如果向上移動所選列表,請更改方向= -1 * https://www.sencha.com/forum/showthread.php?48472-how-to-move-the-grid-s-row-up上下 (我從這里得到了解決方案,只需根據Sencha Touch進行一些更改即可)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM