jqwidgets jqxtree拖放问题

时间:2014-08-08 14:29:53

标签: jquery jqxwidgets

我尝试了两个从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
    });

}

1 个答案:

答案 0 :(得分:1)

拖拉机的主要问题drop函数是无法区分两个树视图的。

我将所有ID值增加到100。 (在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"
                }
                        ]; 
相关问题