0

我试过两棵树,它们的数据是从 json 加载的。每当我使用 json 加载拖放时,都无法按预期工作。该事件始终采用第二棵树。

我尝试从 TreeA 中拖动一个元素,但它从 TreeB 中获取元素。您可以从树下显示的标签中看到哪个被拖动

如果 TreeB 中没有与 TreeA 一样的相应元素,则 TreeA 元素被拖动

我想不通。我认为有些事情与只存储第二个树数据的对象有关..任何帮助将不胜感激:)

下面是相同的小提琴演示

http://jsfiddle.net/tgb1ecLx/

function source(data) {
    var source = {
        datatype: "json",
        datafields: [{
            name: 'id'
        }, {
            name: 'parentid'
        }, {
            name: 'text'
        }, {
            name: 'value'
        }, {
            name: 'expanded'
        }],
        id: 'id',

        localdata: data
    };
    // create data adapter.
    dataAdapter = new $.jqx.dataAdapter(source);
    // perform Data Binding.
    dataAdapter.dataBind();
    // get the tree items. The first parameter is the item's id. The second parameter is the parent item's id. The 'items' parameter represents 
    // the sub items collection name. Each jqxTree item has a 'label' property, but in the JSON data, we have a 'text' field. The last parameter 
    // specifies the mapping between the 'text' and 'label' fields.  
    var records = dataAdapter.getRecordsHierarchy('id', 'parentid', 'items', [{
        name: 'text',
        map: 'label'
    }]);
    // if(tree="fact")
    $('#treeA').jqxTree({
        source: records
    });

}
4

1 回答 1

1

拖放功能的主要问题是无法区分两个树视图。

我将所有ID值增加到一百。(在 TreeB 的数据上)现在作业已正确完成。

我希望这有帮助。

http://jsfiddle.net/tgb1ecLx/10/

 data = [
                    { "id": "102",
                        "parentid": "101",
                        "text": "Tree B Hot Chocolate",
                        "value": "$2.3"
                    }, {
                        "id": "103",
                        "parentid": "101",
                        "text": "Tree B Peppermint Hot Chocolate",
                        "value": "$2.3"
                    }, {
                        "id": "104",
                        "parentid": "101",
                        "text": "Tree B Salted Caramel Hot Chocolate",
                        "value": "$2.3"
                    }, {
                        "id": "105",
                        "parentid": "101",
                        "text": " Tree B White Hot Chocolate",
                        "value": "$2.3"
                    }, {
                        "text": "Tree B Chocolate Beverage",
                        "id": "101",
                        "parentid": "-1",
                        "value": "$2.3"
                }
                        ]; 
于 2014-08-25T18:16:36.023 回答