Sencha touch 使用Sencha Touch处理复杂的业务规则

Sencha touch 使用Sencha Touch处理复杂的业务规则,sencha-touch,extjs,Sencha Touch,Extjs,我感谢大家对我开始使用Sencha Touch的帮助和支持。现在我进入了一些复杂的业务场景处理中,我觉得处理起来要困难得多。这是我的业务需求 成功登录到应用程序后,sencha客户端将收到JSON对象响应,其中包含所有可用的产品和代码。另外,states标记包含排除产品列表。下面是我粘贴的JSON格式示例 我必须有一个表单,在那里我必须显示状态和产品下拉框。UI部分很好。我已经做完了但现在的复杂性是,当我选择一个州时,我必须从所有可用产品中排除产品列表。 我使用了Ajax请求,然后使用解码方法对

我感谢大家对我开始使用Sencha Touch的帮助和支持。现在我进入了一些复杂的业务场景处理中,我觉得处理起来要困难得多。这是我的业务需求

  • 成功登录到应用程序后,sencha客户端将收到JSON对象响应,其中包含所有可用的产品和代码。另外,states标记包含排除产品列表。下面是我粘贴的JSON格式示例

  • 我必须有一个表单,在那里我必须显示状态和产品下拉框。UI部分很好。我已经做完了但现在的复杂性是,当我选择一个州时,我必须从所有可用产品中排除产品列表。

  • 我使用了Ajax请求,然后使用解码方法对JSON响应进行解码。现在我将完整的JSON作为一个对象

  • 我有两个商店,一个是产品清单,另一个是州清单我不要求我的任何商店与服务器同步,因为这会增加数据使用。

  • 选项控制的侦听器也完成了,现在如何操作JSON并动态更新产品存储。请建议。

  • 以下是JSON响应示例:

    {   
        "defaultProducts": {
            "product": [
                {
                    "code": "pro1",
                    "name": "Product AA"
                }, {
                    "code": "pro1",
                    "name": "Product BB"
                }, {
                    "code": "pro1-INP",
                    "name": "Product CC"
                }, {
                    "code": "uni1-sc",
                    "name": "Product DD"
                }, {
                    "code": "pro1",
                    "name": "Product EE"
                }, {
                    "code": "uni1-sc",
                    "name": "TCO - Enhanced"
                }, {
                    "code": "uni1",
                    "name": "Product FF"
                }, {
                    "code": "uni1",
                    "name": "Product GG"
                }
            ]
        },
        "states": {
            "state": [
                {
                    "excludeProducts": {
                        "excludeProduct": [
                            {
                                "code": "pro1",
                                "name": "Product BB"
                            }, {
                                "code": "pro1-INP",
                                "name": "Product CC"
                            }, {
                                "code": "pro1",
                                "name": "Product EE"
                            }, {
                                "code": "uni1",
                                "name": "Product FF"
                            }, {
                                "code": "uni1",
                                "name": "Product GG"
                            }
                        ]
                    },
                    "code": "AL",
                    "name": "Alabama"
                }, {
                    "excludeProducts": {
                        "excludeProduct": [
                            {
                                "code": "pro1",
                                "name": "Product BB"
                            }, {
                                "code": "pro1-INP",
                                "name": "Product CC"
                            }, {
                                "code": "pro1",
                                "name": "Product EE"
                            }, {
                                "code": "uni1",
                                "name": "Product FF"
                            }, {
                                "code": "uni1",
                                "name": "Product GG"
                            }
                        ]
                    },
                    "code": "AK",
                    "name": "Alaska"
                }, {
                    "excludeProducts": {
                        "excludeProduct": [
                            {
                                "code": "pro1",
                                "name": "Product BB"
                            }, {
                                "code": "pro1-INP",
                                "name": "Product CC"
                            }, {
                                "code": "uni1-sc",
                                "name": "Product DD"
                            }, {
                                "code": "pro1",
                                "name": "Product EE"
                            }, {
                                "code": "uni1-sc",
                                "name": "TCO - Enhanced"
                            }
                        ]
                    },
                    "code": "AZ",
                    "name": "Arizona"
                }, {
                    "excludeProducts": {
                        "excludeProduct": [
                            {
                                "code": "pro1",
                                "name": "Product BB"
                            }, {
                                "code": "pro1-INP",
                                "name": "Product CC"
                            }, {
                                "code": "pro1",
                                "name": "Product EE"
                            }, {
                                "code": "uni1",
                                "name": "Product FF"
                            }, {
                                "code": "uni1",
                                "name": "Product GG"
                            }
                        ]
                    },
                    "code": "AR",
                    "name": "Arkansas"
                }
            ]
        },
        "licensedTo": "mycomp.com"
    }
    

    请告诉我其他可以用来实现如此复杂场景的逻辑

    您应该附加侦听器,以便打开状态下拉框,然后根据要排除的项目向产品列表添加筛选器

    以下是状态下拉框中的更改侦听器的外观:

      listeners: {
            change:function(selectfield, value){
                //here you should get reference to the excludeProduct array
                var exProductArray = [];
    
                //then add filter to the product store like this
                productStore.clearFilter(false); // clears previous filters
    
                for(var i=0; i<exProductArray.length;++i){
                  productStore.filter("code",exProductArray[i].code);       
                }              
            }
       },
    
    其中value是this
    value
    object
    change:function(selectfield,value){
    。然后在获得正确的状态记录以获取对productArray的引用后,您应该执行以下操作:

     var exProductArray = stateRecord.excludeProducts.excludeProduct;
    

    您应该附加侦听器,以便打开状态下拉框,然后根据要排除的项目向产品列表添加筛选器

    以下是状态下拉框中的更改侦听器的外观:

      listeners: {
            change:function(selectfield, value){
                //here you should get reference to the excludeProduct array
                var exProductArray = [];
    
                //then add filter to the product store like this
                productStore.clearFilter(false); // clears previous filters
    
                for(var i=0; i<exProductArray.length;++i){
                  productStore.filter("code",exProductArray[i].code);       
                }              
            }
       },
    
    其中value是this
    value
    object
    change:function(selectfield,value){
    。然后在获得正确的状态记录以获取对productArray的引用后,您应该执行以下操作:

     var exProductArray = stateRecord.excludeProducts.excludeProduct;
    

    请不要重定向到链接。事实上,这只是我的帖子。请不要重定向到链接。事实上,这只是我的帖子。@llya139..我尝试过相同的方法,但不起作用。我从json响应中获取了ExpProductArray,然后尝试绕过productStore.filter()但它不起作用。什么不起作用?你能在jsfiddle.net或类似的网站上共享你的代码吗?你收到一些错误消息吗?过滤器没有效果。但是我已经解决了这个问题,手动处理json数据来存储。@llya139..我尝试了同样的方法,但它不起作用。我从json响应中获取了ExpProductArray,然后尝试解决这个问题productStore.filter()但它不起作用。什么不起作用?你能在jsfiddle.net或类似网站上共享你的代码吗?你收到一些错误消息吗?filter无效。但是我已经解决了这个问题,手动处理json数据以存储。