在BB 10 Cascades中交换Listview位置

时间:2013-09-24 05:27:55

标签: qml blackberry-10 blackberry-cascades

我在这里读过一篇http://bbcascadescode.tumblr.com/post/51115772119/swap-function-in-containers的文章,我们可以交换容器组件。我遵循相同的程序,它对我有用。当我为Costume Listview应用相同的程序时,我得到了 “ReferenceError:在控制台上找不到变量:tadawulList”。

Container {
                    id:trade
                    layout: StackLayout {
                        orientation: LayoutOrientation.LeftToRight
                    }
                    topMargin: 10

                    ListView {
                        id: tradeList
                        objectName: "tradeList"
                        dataModel: _app.dataModel
                        visible: true;

                        listItemComponents: [
                            ListItemComponent {
                                type: "header"
                                Header {
                                    title: {
                                        ListItemData
                                    }
                                }
                            },

                            // The tradeList Item
                            ListItemComponent {
                                type: "item"


                                Container {
                                    id:tadawulList
                                    leftPadding: 15.0
                                    rightPadding: 15.0

                                    background: Color.create("#1a1a1a")
                                    preferredHeight: 80.0
                                    topMargin: 6
                                    layout: StackLayout {
                                        orientation: LayoutOrientation.LeftToRight
                                    }

                                    Label {
                                        id: symbol
                                        text: ListItemData.Symbol_En
                                        //text: ListItemData.Symbol_En.length()>20?Symbol_En.subString(0,15): Symbol_En

                                        // Text Style and size etc
                                        textStyle.base: SystemDefaults.TextStyles.SubtitleText
                                        textStyle.fontSizeValue: 5.0
                                        layoutProperties: StackLayoutProperties {
                                            spaceQuota: 3.0
                                        }
                                        verticalAlignment: VerticalAlignment.Center
                                        horizontalAlignment: HorizontalAlignment.Center
                                        textStyle.color: Color.White
                                        textStyle.fontWeight: FontWeight.Bold
                                        textStyle.fontSize: FontSize.PointValue
                                       // multiline: true

                                    }

                                    Container {
                                        id: tadawulchange1
                                        layout: StackLayout {

                                        }

                                        layoutProperties: StackLayoutProperties {
                                            spaceQuota: 2.0

                                        }

                                      //  ListItemData.PerChange.length == 1 ? Color.create("#1a1a1a") :Color.DarkRed

                                      // background: ListItemData.PerChange.indexOf('-') < 0 ?((ListItemData.PerChange.length() == 1) ? Color.create("#1a1a1a") : Color.create("#ff105900")) : ((ListItemData.PerChange.length() == 1) ? Color.create("#1a1a1a") : Color.DarkRed)

                                        background: (ListItemData.PerChange.indexOf('-') < 0 )?((ListItemData.PerChange.indexOf('0.00') <0 ?  Color.create("#ff105900"): Color.create("#1a1a1a"))): ((ListItemData.PerChange.indexOf('0.00') < 0 ?  Color.DarkRed: Color.create("#1a1a1a")))

                                        verticalAlignment: VerticalAlignment.Center
                                        preferredHeight: 20.0
                                        Label {

                                            id: change
                                            text: ListItemData.PerChange
                                           // textStyle.color: ListItemData.PerChange.indexOf('-') < 0 ? Color.Green : Color.Red //here
                                            textStyle.base: SystemDefaults.TextStyles.SubtitleText
                                            textStyle.fontSizeValue: 30.0
                                            layoutProperties: StackLayoutProperties {
                                                spaceQuota: 2
                                            }
                                            verticalAlignment: VerticalAlignment.Center
                                            horizontalAlignment: HorizontalAlignment.Center
                                            preferredHeight: 0.0

                                        }

                                    }

                                    Label {
                                        id: ltp
                                        text: ListItemData.LTP
                                        textStyle.base: SystemDefaults.TextStyles.SubtitleText
                                        textStyle.fontSizeValue: 30.0
                                        layoutProperties: StackLayoutProperties {
                                            spaceQuota: 1
                                        }
                                        verticalAlignment: VerticalAlignment.Center
                                        horizontalAlignment: HorizontalAlignment.Center
                                        textStyle.color: Color.White
                                        textStyle.fontWeight: FontWeight.Default
                                    }
                                    Label {
                                        id: highValue
                                        text: ListItemData.High
                                        textStyle.base: SystemDefaults.TextStyles.SubtitleText
                                        textStyle.fontSizeValue: 30.0
                                        layoutProperties: StackLayoutProperties {
                                            spaceQuota: 1
                                        }
                                        verticalAlignment: VerticalAlignment.Center
                                        horizontalAlignment: HorizontalAlignment.Center
                                        textStyle.color: Color.White
                                        textStyle.fontWeight: FontWeight.Default
                                    }
                                    Label {
                                        id: lowValue
                                        text: ListItemData.Low
                                        textStyle.base: SystemDefaults.TextStyles.SubtitleText
                                        textStyle.fontSizeValue: 30.0
                                        layoutProperties: StackLayoutProperties {
                                            spaceQuota: 1
                                        }
                                        verticalAlignment: VerticalAlignment.Center
                                        horizontalAlignment: HorizontalAlignment.Center
                                        textStyle.color: Color.White
                                        textStyle.fontWeight: FontWeight.Default
                                    }
                                }
                            }
                        ]
                        onTriggered: {
                            var selectedItem = dataModel.data(indexPath);
                            lightTimer.stop();
                            _app.dropSymbols(1); // Drop Req for Tadawul

                            _app.loadQuickWatch(selectedItem.symbol_ID);

                        }
                        onVisibleChanged: {
                            myIndicator.stop();
                            loader.visible = false
                            loadText.visible=false
                        }
                    }
                    }

和myButton Click如下:

                      Button {
                        horizontalAlignment: HorizontalAlignment.Right

                        imageSource: "asset:///images/search_icon.png"
                        preferredWidth: 10.0
                        preferredHeight: 10.0
                        layoutProperties: StackLayoutProperties {
                            spaceQuota: 1.0
                        }
                        onClicked: {                           
                            tadawulList.swap(0, 4);
                            tadawulList.swap(1, 3);
                        }
                    }

请指导我,

感谢!!!

1 个答案:

答案 0 :(得分:0)

交换功能无法实现。但您可以更改布局方向或其他。

以下是如何使用条件更改布局方向的示例代码...

Container {
                property bool isLeft:false
                ListView {
                    id: tradeList
                    objectName: "tradeList"
                    dataModel: _app.dataModel
                    visible: true
                    function getCurrentDirection(){
                        return isLeft;
                    }
                    listItemComponents: [
                        ListItemComponent {
                            type: "header"
                            Header {
                                title: {
                                    ListItemData
                                }
                            }
                        },
                        // The tradeList Item
                        ListItemComponent {
                            type: "item"
                            Container {
                                id: tadawulList
                                layout: StackLayout {
                                // Here is I Changed layout orientation according to value 
                                    orientation: tadawulList.ListItem.view.getCurrentDirection()==true ? LayoutOrientation.LeftToRight : LayoutOrientation.RightToLeft
                                }
                                // Your more UI here
                            }
                        }
                    ]
                }
                Button {
                    onClicked: {
                        isLeft = !isLeft
                        //Refresh your listview here
                    }
                }
            }