Home > other >  The structure member of golang how the initial array structure is empty
The structure member of golang how the initial array structure is empty

Time:09-16

Type Page struct {
The Title string//Title
The Body string//Body
The View int//the View count
IsPublished bool//published or not
OtherPage [] * Page////
}

Var myPage [] * Page

With gorm after the search, is empty or query to but the OtherPage displays is null, the front end, according to the how to OtherPage assignment is empty, let the front-end display []

CodePudding user response:

Null pointer and empty array object is not the same as
Or you could define the OtherPage as arrays,
Namely OtherPage [] Page
Either through myPage, judge OtherPage is nil is assigned an empty array
The
For _, v:=range myPage {
If v.O therPage=nil {
V.O therPage=[...]. * Page {}
}
}

CodePudding user response:

For OtherPage [] Page also not line, or returns null, I used gorm query
Results in OtherPage no value, it shows that Null, is there a better way

CodePudding user response:

As it happens is not!

CodePudding user response:

Please look at the content,,,
  • Related