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

发布于 2024-12-09 15:05:56 字数 4926 浏览 0 评论 0原文

我感谢你们为我开始使用 Sencha Touch 提供的帮助和支持。现在我遇到了一些复杂的业务场景处理,我感觉处理起来比较困难。这是我的业务需求。

  1. 成功登录应用程序后,sencha 客户端会收到 JSON 对象响应,其中包含所有可用的产品和代码。此外,states 标签还包含排除产品列表。我在下面粘贴了 JSON 格式示例。

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

  3. 我使用了Ajax请求并且然后使用 decode 方法来解码 JSON 响应。现在我有了完整的 JSON 作为对象。

  4. 我有 2 家商店,一家用于产品列表,另一家用于州列表。 我不要求我的任何商店与服务器同步,因为这会增加数据使用量。

  5. 用于选项控制的监听器也已完成,现在我如何操作 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"
}

请指导我可以用来实现此类复杂场景的任何其他逻辑。

I appreciate the help and support that you all given me to get started with Sencha Touch. Now i got into some complex business scenarios handling, where i feel much more difficulty to deal with it. Here are my business needs.

  1. On successful login to the application, the sencha client receives the JSON object response where, all the available products and codes are there. Also, the states tag contains the exclude product list. The JSON format sample i have pasted below.

  2. I have to have a form, where i will have to display the states and products drop down box. The UI part is fine. i have done with it. But now the complexity is when i select a state, i have to exclude the list of the products from the total available products.

  3. I have used the Ajax request and then decode method to decode the JSON response. Now i have the complete JSON as an Object.

  4. I have 2 stores, one for products list and other for states list. I don't requires any of my store to be sync with server, as it increases data usages.

  5. Listener for option control is also done, now how can i manipulate the JSON and update the products Store dynamically. Please suggest.

Here is the sample JSON response:

{   
    "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"
}

Please, guide me any other logic that i could use to implement such complex scenarios.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不念旧人 2024-12-16 15:05:56

您应该附加侦听器,以便状态下拉框,然后根据要排除的项目将过滤器添加到产品列表。

状态下拉框中的更改侦听器应如下所示:

  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);       
            }              
        }
   },

要获取对 ProductArray 的引用,您可以将状态下拉列表的 valueField 设置为 code 属性,并设置idProperty 为 code 属性。然后,您可以像这样从状态存储中获取状态记录:

  var stateRecord = stateStore.getById(value);

其中 value 是这个 value 对象 change:function(selectfield, value){。然后,在获得正确的 stateRecord 来获取对 ProductArray 的引用后,您应该执行以下操作:

 var exProductArray = stateRecord.excludeProducts.excludeProduct;

You should attach listener so the state drop down box and then add filters to the product list depending on the items you want to exclude.

This is how your change listener on the state drop down box should look like:

  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);       
            }              
        }
   },

To get reference to the productArray you can set the valueField to the state dropdown list to be the code property and also set the idProperty of the state model to be the code property. Then you can fetch the state record from the states store like this:

  var stateRecord = stateStore.getById(value);

Where value is this value object change:function(selectfield, value){. Then after you get the proper stateRecord to get a reference to the productArray you should just do this:

 var exProductArray = stateRecord.excludeProducts.excludeProduct;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文