使用 Sencha Touch 处理复杂的业务规则
我感谢你们为我开始使用 Sencha Touch 提供的帮助和支持。现在我遇到了一些复杂的业务场景处理,我感觉处理起来比较困难。这是我的业务需求。
成功登录应用程序后,sencha 客户端会收到 JSON 对象响应,其中包含所有可用的产品和代码。此外,states 标签还包含排除产品列表。我在下面粘贴了 JSON 格式示例。
我必须有一个表单,我必须在其中显示状态和产品下拉框。 UI部分很好。我已经完成了。 但现在的复杂性是,当我选择一个州时,我必须从可用产品总数中排除产品列表。
我使用了Ajax请求并且然后使用 decode 方法来解码 JSON 响应。现在我有了完整的 JSON 作为对象。
我有 2 家商店,一家用于产品列表,另一家用于州列表。 我不要求我的任何商店与服务器同步,因为这会增加数据使用量。
用于选项控制的监听器也已完成,现在我如何操作 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.
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.
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.
I have used the Ajax request and then decode method to decode the JSON response. Now i have the complete JSON as an Object.
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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该附加侦听器,以便状态下拉框,然后根据要排除的项目将过滤器添加到产品列表。
状态下拉框中的更改侦听器应如下所示:
要获取对 ProductArray 的引用,您可以将状态下拉列表的 valueField 设置为
code
属性,并设置idProperty 为
code
属性。然后,您可以像这样从状态存储中获取状态记录:其中 value 是这个
value
对象change:function(selectfield, value){
。然后,在获得正确的 stateRecord 来获取对 ProductArray 的引用后,您应该执行以下操作: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:
To get reference to the productArray you can set the valueField to the state dropdown list to be the
code
property and also set theidProperty
of the state model to be thecode
property. Then you can fetch the state record from the states store like this:Where value is this
value
objectchange:function(selectfield, value){
. Then after you get the proper stateRecord to get a reference to the productArray you should just do this: