我应该添加自定义方法到Ext.data.store派生类 [英] Should I add custom methods to Ext.data.store derived classes

查看:110
本文介绍了我应该添加自定义方法到Ext.data.store派生类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全陌生的触摸和伸展。以下是这种情况:



假设您拥有购物车中商品的商店:

  Ext.define('MyApp.store.CardItems',{
extends:'Ext.data.Store',
require:['MyApp.model.CardItem' 'Ext.data.proxy.SessionStorage'],

config:{
model:'MyApp.model.QuoteItem',
autoLoad:true,
autoSync: true,
identifer:'uuid',
proxy:{
type:'sessionstorage',
id:'card'
}
}

});



我知道在sencha store 用于将模型项目列表绑定到网格。我只是想知道是否也可以添加自定义方法到这个类。



例如。假设我们需要一种方法来获取商店中所有商品的总体计数。从OOP的角度来看,我有理由直接在商店上引入这种方法:

  getOverallQuantity:function(){ 
var sum = 0;
this.each(function(item){
sum + = parseInt(item.get('amount'));
},this);
返还金额
}

我只是想知道直接在商店上直接使用这些方法是个好主意或者是因为某些原因避免这种情况?

解决方案

继续Christoph扩展你的课程,这是你的生意OK :)



我正在创建大型的商店/模型/代理层次结构,一切正常。 Sencha基金会(SFC!)它很酷!



干杯,Oleg


I'm totally new to sencha touch and extjs. Here is the scenario:

Suppose you have this store that holds the items on a shopping cart:

Ext.define('MyApp.store.CardItems', {
    extend: 'Ext.data.Store',
    requires: ['MyApp.model.CardItem','Ext.data.proxy.SessionStorage'],

    config :{
        model: 'MyApp.model.QuoteItem',
        autoLoad: true,
        autoSync: true,
        identifer: 'uuid',
        proxy:{
            type:'sessionstorage',
            id:'card'
        }
    }

});

I know that in sencha a store is used to bind a list of model items to a grid for example. I just wonder if it's a good idea to also add custom methods to this class.

For instance. Suppose we need a method to get the overall count of all items in the store. From an OOP point of view it makes sense to me to introduce such method directly on the store:

getOverallQuantity:function () {
    var sum = 0;
    this.each(function (item) {
        sum += parseInt(item.get('amount'));
    }, this);
    return sum;
}

I just wonder if it's a good idea to have those methods directly on the store or if that is to avoid for some reason?

解决方案

Go ahead Christoph with extending your classes, it is your business, it is OK :)

I'm creating large hierarchy of stores/models/proxies and all is working. Sencha Foundation Classes (SFC!) it cool!

Cheers, Oleg

这篇关于我应该添加自定义方法到Ext.data.store派生类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆