sencha touch change model data of store but load function not work

本文探讨了在Sencha框架中如何解决修改Store内模型数据后仍能接收服务器新数据的问题。通过重写mergeData方法并调整判断逻辑,确保已手动修改的数据项能够在Store加载新数据时被覆盖。

In the process of my project development,I need to change data of model stored in store of  one list,in order to refresh the list without any unnesscary ajax request.But  after you changed the model in store,when your store load data again,the returned data can not bind to the store.It means that your store could not load new data from server,it show the modified data that you set manually.

Follows is the source code:

 1  mergeData: function(rawData) {
 2         var me = this,
 3             fields = me.getFields().items,
 4             ln = fields.length,
 5             data = me.data,
 6             i, field, fieldName, value, convert;
 7 
 8         for (i = 0; i < ln; i++) {
 9             field = fields[i];
10             fieldName = field.getName();
11             convert = field.getConvert();
12             value = rawData[fieldName];
13 
14             if (value !== undefined && !me.isModified(fieldName)) {//if field is modified,Sencha will do nothing and mantains the dirty data that you                                            //changed manually
15                 if (convert) {
16                     value = convert.call(field, value, me);
17                 }
18 
19                 data[fieldName] = value;
20             }
21         }
22 
23         return this;
24     },
    isModified : function(fieldName) {
        return this.modified.hasOwnProperty(fieldName);
    }

Sencha use this method to judge fields if not modified. And now we want the changed fields be bind data from server,so we just set model.modified={} after you change your data.It works well;

 

转载于:https://www.cnblogs.com/fengjian/archive/2013/03/22/2975051.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值