在sencha touch中过滤2

时间:2012-07-21 07:43:30

标签: sencha-touch-2

我正在使用Sencha Touch 2.使用store.filter时,所有te记录都会被过滤掉。

基本上我有一个主题列表。当我点击某个特定主题时,我想显示该特定主题的评论列表。我使用了2家商店。存储主题和topicID的一个。其他存储评论主题,评论,主题ID和评论ID。因此,当我披露特定主题时,我使用其topicID来过滤我的评论商店

//这是我的主要主题列表视图

Ext.define("ForumApp.view.ForumList", {
extend: "Ext.navigation.View",
requires:["Ext.dataview.List", "Ext.Toolbar", "Ext.field.Text", "Ext.field.TextArea"],
xtype: "forumlistview",

config: {
    items: [{
        xtype: "toolbar",
        title: "Forum",
        docked: "top",
        items: [
                {
                    xtype: "button",
                    ui: "back",
                    action:'backButton',
                    text: "Logout"
                },
            { xtype: 'spacer' },
            {
                xtype: "button",
                text: 'New',
                ui: 'action',
                itemId: "newButton"
            }
        ]
    }, {
        xtype: "list",
        title:"welcome",
        store: "ForumStore",
        itemId:"notesList",
        loadingText: "Loading Notes...",
        emptyText: "<div class=\"notes-list-empty-text\">No notes found.</div>",
        onItemDisclosure: true,
        grouped: true,
        itemTpl: "<div class=\"list-item-title\">{title}</div>"       
    }],
    listeners: [{
        delegate: "#newButton",
        event: "tap",
        fn: "onNewButtonTap"
    }, {
        delegate: "#notesList",
        event: "disclose",
        fn: "onNotesListDisclose"
    }]
},    
onNewButtonTap: function () {
    console.log("newTopicCommand");
    this.fireEvent("newTopicCommand", this);
},
onNotesListDisclose: function (list, record, target, index, evt, options) {
    console.log("topicViewCommand");
    this.fireEvent('topicViewCommand', this, record);
  }
});

//这是我的评论列表视图

  Ext.define("ForumApp.view.TopicComment", {
 extend: "Ext.Container",
 requires: "Ext.form.FieldSet",
 alias: "widget.topiccommentview",
 config: {
    scrollable: 'vertical',
    fullscreen: true,
    layout: "vbox",
    tpl: "  Topic started by '{username}' :{narrative}",

    items: [
        {
            xtype: "list",
            itemId: "commentlist",
            itemTpl: "{title} : {username} : {narrative}",
            store: "CommentStore",
            flex: 1,
        },
        {
                    docked: "bottom",
                    xtype: "button",
                    action:'comButton',
                    ui: "confirm",
                    text: "Comment",
        }
    ]
 }
 });

//这是我的控制器

 Ext.define("ForumApp.controller.ForumController", {

extend: "Ext.app.Controller",
config: {
    refs: {
        forumListView: "forumlistview",
        commentList: "#commentlist"
    },
    control: {
        forumListView: {
            topicViewCommand: "onTopicViewCommand"
        }
        }
},

onTopicViewCommand: function (list, record) {

    this.getCommentList().getStore().clearFilter();
    this.getCommentList().getStore().filter([{property:'id',value: record.data.id}]);

    this.getForumListView().push({
    xtype: 'topiccommentview',
    title: record.titleName(),
    data: record.data
    });
},

// Base Class functions.
launch: function () {
    this.callParent(arguments);
    var forumStore = Ext.getStore("ForumStore");
    forumStore.load();
    var commentStore = Ext.getStore("CommentStore");
    commentStore.load();
    var userStore = Ext.getStore("UserStore");
    userStore.load();
},
init: function () {
    this.callParent(arguments);
}
 });

//这是我的评论模型

  Ext.define("ForumApp.model.CommentModel", {
extend: "Ext.data.Model",
config: {
    idProperty: 'commentId',
    fields: [
        { name: 'commentId', type: 'int' },
        { name: 'id', type: 'int' },
        { name: 'dateCreated', type: 'date', dateFormat: 'c' },
        { name: 'title', type: 'string' },
        { name: 'username', type: 'string' },
        { name: 'narrative', type: 'string' }
    ],
    validations: [
        { type: 'presence', field: 'id' },
        { type: 'presence', field: 'commentId' },
        { type: 'presence', field: 'dateCreated' },
        { type: 'presence', field: 'title', message: 'Please enter a title for this note.' }
    ]
},
titleName: function(){
    var d=this.data,
    names=[
        d.title
        ];
        return names;
}
  });

//这是我的评论商店

  Ext.define("ForumApp.store.CommentStore", {
extend: "Ext.data.Store",
requires: "Ext.data.proxy.LocalStorage",
config: {
    model: "ForumApp.model.CommentModel",
    proxy: {
        type: 'localstorage',
        id: 'comment-store-2'
    },
    sorters: [{ property: 'dateCreated', direction: 'DESC'}],
    grouper: {
        sortProperty: "dateCreated",
        direction: "DESC",
        groupFn: function (record) {

            if (record && record.data.dateCreated) {
                return record.data.dateCreated.toDateString();
            } else {
                return '';
            }
        }
    }
   }
 });

0 个答案:

没有答案