json 将值加载到 extjs checkboxgroup 网格编辑器中

发布于 2024-09-29 19:48:14 字数 2181 浏览 3 评论 0原文

我需要设置一个 CheckboxGroup 复选框,其中包含从某个 url 加载 json 的值。 JSON 的正确格式是什么?

非常感谢您的帮助!

更新:我会澄清我的问题。

我正在使用 EditorGridPanel。行是句点。有“Start_at”、“Finish_at”、“Region”列。第一个和第二个是日期,一切都很好。 Region 的问题实际上是一个 CheckboxGroup,每个工作日都有一个复选框 - 星期一、星期二等。所以:

首先我将数据从服务器加载到商店中

function setupDataSource() {
    row = Ext.data.Record.create([
        { name: 'start_at', type: 'string' },
        { name: 'finish_at', type: 'string' },
        { name: 'region', type: 'string' }
    ]);      

    store = new Ext.data.Store({
        url: '/country/195/periods',
        reader: new Ext.data.JsonReader(
            {
                root: 'rows',
                id: 'id'
            }, 
            row
        )
    });

    store.load();

}

URL url: '/country/195/periods' 返回 JSON:

{"rows": [{"region": {"cbvert_1": 1, "cbvert_2": 0, "cbvert_3": 1, "cbvert_4": 0, "cbvert_5": 1, "cbvert_6": 0, "cbvert_7": 1}, "start_at": "2010-10-17", "id": 1, "finish_at": "2010-10-28"}]}

然后我正在构建一个网格:

function buildGrid() { 

    sm = new Ext.grid.RowSelectionModel();     
    cm = new Ext.grid.ColumnModel([

        // ... Start at and Finish at columns definition here ...

        { header: 'Region',
          dataIndex: 'region', 
            width: 150, 
            editor: new Ext.form.CheckboxGroup({    
            xtype: 'checkboxgroup',
        columns: 7,
        vertical: true,
        items: [
           {boxLabel: 'M', name: 'cbvert_1', inputValue: 1},
           {boxLabel: 'T', name: 'cbvert_2', inputValue: 1},
           {boxLabel: 'W', name: 'cbvert_3', inputValue: 1},
           {boxLabel: 'T', name: 'cbvert_4', inputValue: 1},
           {boxLabel: 'F', name: 'cbvert_5', inputValue: 1},
           {boxLabel: 'S', name: 'cbvert_6', inputValue: 1},
           {boxLabel: 'S', name: 'cbvert_7', inputValue: 1},
                    ]
                }),
            renderer: function(value) {}
        }]);  

     // ...

}

因此,当我单击网格单元格时,我需要使用先前存储在数据库中的值来预先选择复选框。现在所有复选框均保持空白,但应为 1010101,如 JSON 中所示。

请指出错误或者某种解决方案。任何帮助将不胜感激。 非常感谢!

I need to set up a CheckboxGroup checkboxes with values loaded with json from some url.
What is a correct format of JSON?

Many thanks for help!

Update: I'll clarify my problem.

I'm using EditorGridPanel. Rows are Periods. There are columns Start_at, Finish_at, Region. First and second are date and everything ok with them. Problem with Region which actually is a CheckboxGroup with a checkbox for each week day - Monday, Tuesday, etc. So:

First I'm loading data from server into store

function setupDataSource() {
    row = Ext.data.Record.create([
        { name: 'start_at', type: 'string' },
        { name: 'finish_at', type: 'string' },
        { name: 'region', type: 'string' }
    ]);      

    store = new Ext.data.Store({
        url: '/country/195/periods',
        reader: new Ext.data.JsonReader(
            {
                root: 'rows',
                id: 'id'
            }, 
            row
        )
    });

    store.load();

}

URL url: '/country/195/periods' returns JSON:

{"rows": [{"region": {"cbvert_1": 1, "cbvert_2": 0, "cbvert_3": 1, "cbvert_4": 0, "cbvert_5": 1, "cbvert_6": 0, "cbvert_7": 1}, "start_at": "2010-10-17", "id": 1, "finish_at": "2010-10-28"}]}

Then I'm building a grid:

function buildGrid() { 

    sm = new Ext.grid.RowSelectionModel();     
    cm = new Ext.grid.ColumnModel([

        // ... Start at and Finish at columns definition here ...

        { header: 'Region',
          dataIndex: 'region', 
            width: 150, 
            editor: new Ext.form.CheckboxGroup({    
            xtype: 'checkboxgroup',
        columns: 7,
        vertical: true,
        items: [
           {boxLabel: 'M', name: 'cbvert_1', inputValue: 1},
           {boxLabel: 'T', name: 'cbvert_2', inputValue: 1},
           {boxLabel: 'W', name: 'cbvert_3', inputValue: 1},
           {boxLabel: 'T', name: 'cbvert_4', inputValue: 1},
           {boxLabel: 'F', name: 'cbvert_5', inputValue: 1},
           {boxLabel: 'S', name: 'cbvert_6', inputValue: 1},
           {boxLabel: 'S', name: 'cbvert_7', inputValue: 1},
                    ]
                }),
            renderer: function(value) {}
        }]);  

     // ...

}

So, when I'm clicking on a grid cell I need to get checkboxes preselected with values previously stored in database. Now all checkboxes are stay blank but should be 1010101 as its in JSON.

Please point me to errors or maybe a some kind of a solution. Any help will be greatly appreciated.
Many thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空‖城人不在 2024-10-06 19:48:14

看看这个:
http://www.sencha.com/forum/showthread .php?47243-Load-data-in-checkboxgroup

更新:
删除区域字段的类型声明。您不需要字符串,而是对象(来自 JSON)。这样就可以正常工作了:)

Check this out:
http://www.sencha.com/forum/showthread.php?47243-Load-data-in-checkboxgroup

Updated:
Remove the type declaration of the region field. You do not need a string but an object (from JSON). It works just fine that way :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文