如何更新收集数据并使用Backbone Marionette重新渲染

时间:2016-04-26 18:48:11

标签: javascript backbone.js marionette

我知道它之前已被废弃但我仍然无法找到解决方案。

我的视图工作正常,但是在事件(updateClicked)上我想调用服务器进行更新。服务器将返回完整列表。 更新集合并重新渲染视图的最佳做法是什么。

由于

仅供参考我使用requirejs

模型

CommonEntities.Item = Backbone.Model.extend({  
});
CommonEntities.Items = Backbone.Collection.extend({
        model: CommonEntities.Item
}); 

getCommonDataModalAll: function(url) {   
               var defer = $.Deferred();
               var ajax = $.ajax({
                   url: url,
                   type: 'GET'
               });
               ajax.done(function (Data) {
                    var source= new CommonEntities.Item();
                    source.set(Data);
                    defer.resolve(source);
               });
               ajax.fail(function(jqXHR, textStatus, errorThrown) {
                    defer.reject(errorThrown);
              });
               return defer.promise();
            }

Main.reqres.setHandler("common:getCollection", function(url) {
        return API.getCommonDataCollection(url);
    });

控制器

 var fetchingData = Main.request("common:getCollection",'my_url');
                fetchingData.done(function (Collection) {
                    var table = new ListPage.Notes({
                        collection: Collection
                    });
                    Main.MainRegion.show(table);
                });

查看

 ListPage.Item = Marionette.ItemView.extend({
                initialize:function () {
                },
                className: "note",
                template: BodyTpl,
                tagName: "tr"
            });
            ListPage.Notes = Marionette.CompositeView.extend({
                template: HeadTpl,
                tagName: "table",
                className: "row table table-hover",
                childViewContainer: "tbody",
                childView: ListPage.Item,
                events: {
                    "click .s-update": "updateClicked",
                },
                 updateClicked: function (e) {
                    e.stopPropagation();
                    //some jquery logic
                    //update the server 
                    //how to call the server?
                },
            });

1 个答案:

答案 0 :(得分:0)

我会这样做:

<tablename>_id