开发者

Updating Child Panels in Sencha Touch MVC App

Developing a Sencha Touch MVC app that pulls data from json store (thats set up to a DB pulling out content from a Wordpress Blog).

Everything works up until my "detail" panel. Instead of it listening to the TPL, its just dumping some data. The data looks similar to my blog post, but is filled with other code and doesn't make much sense.

Here is a lean version of my list:

    myApp.views.PostListView = Ext.extend(Ext.Panel, {

    postStore: Ext.emptyFn,
    postList: Ext.emptyFn,
    id:'postlistview',
    layout: 'card',

    initComponent: function () {

       /* this.newButton = new Ext.Button({
            text: 'New',
            ui: 'action',
            handler: this.onNewNote,
            scope: this
        });*/

        this.topToolbar = new Ext.Toolbar({
            title: 'All Posts',
           /* items: [
                { xtype: 'spacer' },
                this.newButton
            ],*/
        });


        this.dockedItems = [ this.topToolbar ];

        this.postList = new Ext.List({
            store: myApp.stores.postStore,
            grouped: true,
            emptyText: '<div style="margin:5px;">No notes cached.</div>',
            onItemDisclosure: true,
            itemTpl: '<div class="list-item-title">{title}</div>' +
                            '<div class="list-item-narrative"><small>{body}</small></div>',

        });

        this.postList.on('disclose', function (record) {
            this.onViewPost(record);
        }, this),

        this.items = [this.postList];

        myApp.views.PostListView.superclass.initComponent.call(this);
    },
    onViewPost: function (record) {
        Ext.dispatch({
            controller: myApp.controllers.masterController,
            action: 'viewpost',
            post: record
        });
    },
});

And here is the "detail" view that is called on disclosure:

myApp.views.PostSingleView = Ext.extend(Ext.Panel, { 

    title:'Single Post',
    id:'postsingleview',
    layout:'card',
    style:'background:grey;',

    initComponent: function () {

        this.new1Button = new Ext.Button({
            text: 'Back',
            ui: 'back',
            handler: this.onViewList,
            scope: this,
            dock:"left"
        });

        this.top1Toolbar = new Ext.Toolbar({
            items: [
                this.new1Button
            ],

            title: 'Single Posts',
        });

        this.postSinglePanel = new Ext.Panel({
            layout:'fit',
            flex:1,
            scroll: 'vertical',
            style:'padding:10px;background:yellow;',
            itemTpl: '<tpl for=".">' +
                        '<div class="list-item-narrative">{body}</div>' +
                     '</tpl>',
        });

        this.dockedItems = [ this.top1Toolbar, this.postSinglePanel ];

        myApp.views.PostSingleView.superclass.initComponent.call(this);
    },

    onViewList: function () {
        Ext.dispatch({
            controller: myApp.controllers.masterController,
            action: 'viewlist',

        });
    },
});

And here is the controller that its talking to:

    Ext.regController('masterController', {


    'index': function (options) {

        if (!myApp.views.mainView) {
            myApp.views.mainView = new myApp.views.MainView();
        }

        myApp.views.mainView.setActiveItem(
            myApp.views.postView
        );
    },

    'viewpost': function (options) {

        myApp.views.postSingleView.postSinglePanel.update(options.post);
        myApp.views.postView.setActiveItem(
            myApp.views.postSingleView,
            { type: 'slide', direction: 'left' }
        );
    },

});

myApp.controllers.masterController = Ext.ControllerManager.get('masterController');

When the data comes out, it looks similar to this:

http://i.imgur.com/QlQG8.png

(the black boxes are "redacted" content, no error code there).

In closing, I believe that the controller is "dumping" the data into "MyApp.views.PostSingleView" rather than formatting it as I request in the TPL, though I'm not sure how to fix it. Any and all help MUCH appreciated!

UPDATE: As requested, here is the RegModel:

    Ext.regModel("CategoryModel", {
    fields: [
        {name: "id", type: "int"},
        {name: "title", type: "string"},
        {name: "body", type: "string"},
    ],
    hasMany: {
        model: 'Post',
        name: 'posts'
    }
});

And here is a sample of the json:

{
   "status":"ok",
   "post":{
      "id":1037,
      "type":"post",
      "slug":"post-title",
      "url":"http:\/\/localhost:8888\/jsontest\/PostTitle\/",
      "status":"publish",
      "title":"Post Title",
      "title_plain":"Post Title",
      "conte开发者_如何学运维nt":"<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br \/>\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<\/p>\n<!-- PHP 5.x -->",
      "excerpt":"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat [...]",
      "date":"2011-07-29 14:17:31",
      "modified":"2011-08-30 01:33:20",
      "categories":[
         {
            "id":87,
            "slug":"the-category",
            "title":"The Category",
            "description":"",
            "parent":17,
            "post_count":5
         }
      ],
      "tags":[

      ],
      "author":{
         "id":2,
         "slug":"tom",
         "name":"tom",
         "first_name":"tom",
         "last_name":"",
         "nickname":"",
         "url":"",
         "description":""
      },
      "comments":[

      ],
      "attachments":[

      ],
      "comment_count":0,
      "comment_status":"open"
   },
   "previous_url":"http:\/\/localhost:8888\/jsontest\/next-post\/",
   "next_url":"http:\/\/localhost:8888\/jsontest\/prev-post\/"
}


Use the tpl config option of the Ext.Panel not the itemTpl which doesn't exist.

As someone has mentioned before, be careful when using a Model instance and the update method, you will need to use the model's data property.


Try using this:

myApp.views.postSingleView.postSinglePanel.update(options.post.data);

the reason is that post does not actually expose the underlying data directly, you need to use the property data for that.

Also any particular reason why you are docking the postSinglePanel? I would be very careful using too many docked items as they are a known source of bugs and layout issues.


A simple way is to write your own method to update child panels (you can also see to override the default update method)

myApp.views.PostSingleView = Ext.extend(Ext.Panel, { 
   initComponent: function () {
      // [...]
   },

   // [...]

   myUpdate: function(data) {
      this.postSinglePanel.update(data);
      this.doComponentLayout(); // not sure if necessary...
   }
});

and from your controller:

Ext.regController('masterController', {
    // [...]
    'viewpost': function (options) {

        myApp.views.postSingleView.myUpdate(options.post.data); // note the .data
        // [...]
    },

});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜