Model view controller 使用从jsp获取的动态数据

Model view controller 使用从jsp获取的动态数据,model-view-controller,sencha-touch,Model View Controller,Sencha Touch,在下面的代码中,我在嵌套列表中获取静态数据。但我需要动态数据,即从jsp获取的数据,而不是静态数据。我不知道怎么做 Ext.define('SenchaApp.store.Items', { extend: 'Ext.data.TreeStore', config: { model: 'SenchaApp.model.Item', defaultRootProperty: 'items', root: {

在下面的代码中,我在嵌套列表中获取静态数据。但我需要动态数据,即从jsp获取的数据,而不是静态数据。我不知道怎么做

Ext.define('SenchaApp.store.Items', {
    extend: 'Ext.data.TreeStore',

    config: {
        model: 'SenchaApp.model.Item',
        defaultRootProperty: 'items',
        root: {
            items: [
            {
                text: 'Categories1',
                items: [
                    {
                        text: 'Subcategories1',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },
                    {
                        text: 'Subcategories2',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },
                    {
                        text: 'Subcategories3',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },
                    {
                        text: 'Subcategories4',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },

                ]
            },
            {
                text: 'Categories2',
                items: [
                    {
                        text: 'Subcategories1',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },
                    {
                        text: 'Subcategories2',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },
                    {
                        text: 'Subcategories3',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },
                    {
                        text: 'Subcategories4',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },

                ]
            },
             {
                text: 'Categories3',
                items: [
                    {
                        text: 'Subcategories1',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },
                    {
                        text: 'Subcategories2',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },
                    {
                        text: 'Subcategories3',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },
                    {
                        text: 'Subcategories4',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },

                ]
            },
             {
                text: 'Categories4',
                items: [
                    {
                        text: 'Subcategories1',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },
                    {
                        text: 'Subcategories2',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },
                    {
                        text: 'Subcategories3',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },
                    {
                        text: 'Subcategories4',
                        items: [
                            { text: 'Product1', leaf: true },
                            { text: 'Product2', leaf: true },
                            { text: 'Product3', leaf: true },
                            { text: 'Product4', leaf: true }
                        ]
                    },

                ]
            },
        ]
    }
    }
});

实际上,您不必在这里使用JSONP。通过JSON读取器使用Ajax请求要容易得多

根据您的代码,我认为您的模型定义应该是这样的:

Ext.define('SenchaApp.model.Item', {
        extend: 'Ext.data.Model',
        config: {
            fields: ['text'],
        }
});
然后,这将从服务器获取JSONP并填充您的存储:

Ext.define('SenchaApp.store.Items', {
    extend: 'Ext.data.TreeStore',

    config: {
        model: 'SenchaApp.model.Item',
        proxy: {
            type: 'ajax',
            url: enter_your_api_url_here,
            extraParams: {set your extra params if needed},
            reader: {
                type: 'json',
                rootProperty: 'items'
            }
        },
        autoLoad: true,
    }
});
希望能有帮助


PS:如果它不起作用,请在这里复制并粘贴您的jsonp文件链接,我会帮助您。

实际上您不必在这里使用jsonp。通过JSON读取器使用Ajax请求要容易得多

根据您的代码,我认为您的模型定义应该是这样的:

Ext.define('SenchaApp.model.Item', {
        extend: 'Ext.data.Model',
        config: {
            fields: ['text'],
        }
});
然后,这将从服务器获取JSONP并填充您的存储:

Ext.define('SenchaApp.store.Items', {
    extend: 'Ext.data.TreeStore',

    config: {
        model: 'SenchaApp.model.Item',
        proxy: {
            type: 'ajax',
            url: enter_your_api_url_here,
            extraParams: {set your extra params if needed},
            reader: {
                type: 'json',
                rootProperty: 'items'
            }
        },
        autoLoad: true,
    }
});
希望能有帮助


PS:如果它不起作用,请复制并粘贴您的jsonp文件链接到这里,我会帮助您。

在上面的代码中,您显示了一个包含填充数据的内联存储。你说的“动态”是什么意思?这就是发送JSONP请求,获取嵌套列表数据并填写嵌套列表组件吗?是的。我想从jsp获取数据。我硬编码数据,但我想从jspi获取数据。我对senchatouch是新手。我不知道如何在senchatouch中使用jsp。我们如何将jsp数据转换为JSONP。在上面的代码中,显示一个包含填充数据的内联存储。你说的“动态”是什么意思?这就是发送JSONP请求,获取嵌套列表数据并填写嵌套列表组件吗?是的。我想从jsp获取数据。我硬编码数据,但我想从jspi获取数据。我是senchatouch的新手。我不知道如何在senchatouch中使用jsp。我们如何将jsp数据转换为JSONP。如果您对答案感到满意,根据Stack Overflow的规则,您应该对其进行投票并将其检查为已接受的答案以关闭此问题。如果您对答案感到满意,您应该根据Stack Overflow的规则对其进行投票并将其检查为已接受的答案以关闭此问题