Просто добавление к вышеприведенному ответу. Вы можете определить функцию для инкапсуляции сложности defineProperty, как указано ниже.
var defineProp = function ( obj, key, value ){
var config = {
value: value,
writable: true,
enumerable: true,
configurable: true
};
Object.defineProperty( obj, key, config );
};
//Call the method to add properties to any object
defineProp( data, "PropertyA", 1 );
defineProp( data, "PropertyB", 2 );
defineProp( data, "PropertyC", 3 );
ссылка: http://addyosmani.com/resources/essentialjsdesignpatterns/book/#constructorpatternjavascript
Люди, у меня было много опыта, но почти ничего не получалось, пока я не нашел этот пост https://evileg.com/en/post/191/ , который помог мне, и я использовал, чтобы повернуть меню по горизонтали, чтобы вертикали. ниже приведен код, который я использовал.
Большое спасибо!
// Layer with buttons that will change the fragments
RowLayout {
id: rowLayout
anchors.top: parent.top
anchors.left: parent.left
anchors.leftMargin: 0
anchors.margins: 15
Button {
id: button1
anchors.left: rowLayout.left
text: qsTr("Fragment 1")
// Download the component from a file
onClicked: loader.source = "Fragment1.qml"
}
Button {
id: button2
anchors.left: rowLayout.left
anchors.top: button1.bottom
text: qsTr("Fragment 2")
// Loading setSource component through the method of installing the fragment parameters
onClicked: loader.setSource("Fragment2.qml")
}
Button {
id: button3
anchors.left: rowLayout.left
anchors.top: button2.bottom
text: qsTr("Fragment 3")
// Loading setSource component through the method of installing the fragment parameters
onClicked: loader.setSource("Fragment3.qml")
}
Button {
id: button4
anchors.left: rowLayout.left
anchors.top: button3.bottom
text: qsTr("Fragment 4")
// Installing a fragment from the Component
onClicked: loader.sourceComponent = fragment4
}
Button {
id: button5
anchors.left: rowLayout.left
anchors.top: button4.bottom
text: qsTr("Fragment 5")
// Installing a fragment from the Component
onClicked: loader.sourceComponent = fragment5
}
}
Loader {
id: loader
anchors.top: rowLayout.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.topMargin: -40
anchors.leftMargin: 63
source: "Fragment1.qml"
}