ykksqq520
2011-08-31 14:44 阅读 182

请问一个EXT绑定数据的问题

数据始终无法读出来,取出来的JSON为[count:7,items:[{"Slots":null,"Id":4,"DisplayOrder":100,"ChannelName":"6ur","ChannelDesc":"utr"},{"Slots":null,"Id":5,"DisplayOrder":100,"ChannelName":"345345","ChannelDesc":"23423"},{"Slots":null,"Id":6,"DisplayOrder":100,"ChannelName":"345345","ChannelDesc":"23423"},{"Slots":null,"Id":7,"DisplayOrder":100,"ChannelName":"345345","ChannelDesc":"23423"},{"Slots":null,"Id":8,"DisplayOrder":100,"ChannelName":"345345","ChannelDesc":"23423"},{"Slots":null,"Id":9,"DisplayOrder":100,"ChannelName":"345345","ChannelDesc":"23423"},{"Slots":null,"Id":10,"DisplayOrder":1,"ChannelName":"ertert","ChannelDesc":"rgdg"}]]

Ext.define('local', {
extend: 'Ext.data.Model',
fields: ['ChannelName', 'ID', 'ChannelDesc', 'DisplayOrder', 'Slots']
});

Ext.define('Gotogether.Advertisement.ChannelList', {
extend: 'Ext.panel.Panel',
alias: 'widget.channellist',
title: '频道',
collapsible: true,
animCollapse: true,
margins: '5 0 5 5',
layout: 'fit',
initComponent: function () {
Ext.apply(this, {
items: [{
xtype: 'dataview',
trackOver: true,
store: returnStore(),
model: 'local',
itemSelector: '.feed-list-item',
overItemCls: 'feed-list-item-hover',
tpl: '

{ChannelName}
',
listeners: {
selectionchange: this.onSelectionChange,
scope: this
}
}]
});
this.callParent(arguments);
},

onSelectionChange: function (selmodel, selection) {
    var selected = selection[0],
        button = this.down('button[action=remove]');
    if (selected) {
        button.enable();
    }
    else {
        button.disable();
    }
}

});

function returnStore() {
var proxy1 = new Ext.data.HttpProxy({
type :'ajax',
method: 'get',
url: '../../handler/ChannelHandler.ashx?method=listChannel'
});
var reader1 = new Ext.data.JsonReader({
count : 'count',
root: 'items'
},
[
{ name: 'ChannelName', mapping: 'ChannelName' },
{ name: 'ID', mapping: 'ID' }
]
);
// 构建Store

var store = new Ext.data.Store({
proxy: proxy1,
reader: reader1
});
// 载入
return store;
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

9条回答 默认 最新

  • 已采纳
    myali88 myali88 2011-08-31 18:10

    [quote]
    用你写的代码可以,不过我想知道我写的哪里出了问题
    [/quote]
    没办法复原你的执行情况,我也很难知道原因。还有你页面加载后,reader的请求是否发出呢,是不是没有设置“autoLoad”的原因啊?

    点赞 评论 复制链接分享
  • AngelAndAngel AngelAndAngel 2011-08-31 14:47

    报错还是怎样?

    点赞 评论 复制链接分享
  • myali88 myali88 2011-08-31 16:25

    [code="java"]
    [count:7,items:[{"Slots":null,"Id":4,"DisplayOrder":100,"ChannelName":"6ur","ChannelDesc":"utr"},{"Slots":null,"Id":5,"DisplayOrder":100,"ChannelName":"345345","ChannelDesc":"23423"},{"Slots":null,"Id":6,"DisplayOrder":100,"ChannelName":"345345","ChannelDesc":"23423"},{"Slots":null,"Id":7,"DisplayOrder":100,"ChannelName":"345345","ChannelDesc":"23423"},{"Slots":null,"Id":8,"DisplayOrder":100,"ChannelName":"345345","ChannelDesc":"23423"},{"Slots":null,"Id":9,"DisplayOrder":100,"ChannelName":"345345","ChannelDesc":"23423"},{"Slots":null,"Id":10,"DisplayOrder":1,"ChannelName":"ertert","ChannelDesc":"rgdg"}]]
    [/code]
    我怎么看着你这个json数据格式不对呢,最外边不是应该是大括号的么?

    点赞 评论 复制链接分享
  • myali88 myali88 2011-08-31 17:00

    [code="java"]
    var store = new Ext.data.Store({
    model : 'local',
    proxy: proxy1,
    reader: reader1
    });
    [/code]
    你这个store,是不是应该把上面定义的model设置进去呢!

    点赞 评论 复制链接分享
  • myali88 myali88 2011-08-31 17:18

    [quote]可惜没数据[/quote]
    我觉得应该还是你json格式可能有问题,你返回的json应该把“count”属性加上,再试试。

    点赞 评论 复制链接分享
  • ruanguoxiang0107 ruanguoxiang0107 2011-08-31 17:24

    :wink:

    点赞 评论 复制链接分享
  • myali88 myali88 2011-08-31 17:30

    [code="java"]
    var reader1 = new Ext.data.JsonReader({
    count : 'count',
    root: 'items'
    },
    [
    { name: 'ChannelName', mapping: 'ChannelName' },
    { name: 'ID', mapping: 'ID' }
    ]
    );
    [/code]
    这个写法不对吧,JsonReader的构造函数怎么会传两个参数呢?你改成:
    [code="java"]
    var reader1 = new Ext.data.JsonReader({
    count : 'count',
    root: 'items',
    model: 'User'
    }
    );
    [/code]
    这样试试。

    点赞 评论 复制链接分享
  • myali88 myali88 2011-08-31 17:31

    把model名字改成你的“local”,不是‘User’

    点赞 评论 复制链接分享
  • myali88 myali88 2011-08-31 17:59

    [code="java"]
    Ext.require(['*']);

    Ext.define('Channel', {
    extend: 'Ext.data.Model',
    fields: ['ChannelName', 'ID', 'ChannelDesc', 'DisplayOrder', 'Slots']
    });

    Ext.define('Gotogether.Advertisement.ChannelList', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.channellist',
    title: '频道',
    collapsible: true,
    animCollapse: true,
    margins: '5 0 5 5',
    layout: 'fit',
    initComponent: function () {
    var me = this ,
    store = Ext.create('Ext.data.Store', {
    model: 'Channel',
    proxy: {
    type: 'ajax',
    url : 'channels.json',
    reader: {
    type: 'json',
    root: 'items'
    }
    },
    autoLoad: true
    });

        Ext.apply(me, {
            items: [{
                xtype: 'dataview',
                trackOver: true,
                store: store,
                model: 'Channel',
                itemSelector: '.feed-list-item',
                overItemCls: 'feed-list-item-hover',
                tpl: '<tpl for="."><div class="feed-list-item">{ChannelName}</div></tpl>',
                listeners: {
                    selectionchange: me.onSelectionChange,
                    scope: me
                }
            }]
        });
        me.callParent(arguments);
    },
    
    onSelectionChange: function (selmodel, selection) {
        var selected = selection[0],
            button = this.down('button[action=remove]');
        if (selected) {
            button.enable();
        }
        else {
            button.disable();
        }
    }
    

    });

    Ext.onReady(function() {
    Ext.create('Gotogether.Advertisement.ChannelList' , {renderTo : Ext.getBody()});
    });
    [/code]
    我用chanels.json文件测试了一下,上面的代码是可以的。

    点赞 评论 复制链接分享

相关推荐