Bläddra i källkod

修复排序问题

fancl 3 år sedan
förälder
incheckning
35b3b98e84
2 ändrade filer med 4 tillägg och 5 borttagningar
  1. 1 3
      crud.go
  2. 3 2
      entity.go

+ 1 - 3
crud.go

@@ -244,9 +244,7 @@ func (crud *CRUD) Attach(model Model, ops ...Option) (err error) {
 		return
 		return
 	}
 	}
 	scenarios := model.Scenario()
 	scenarios := model.Scenario()
-	atomic.AddInt32(&crud.index, 1)
-	entity := newEntity(model, opts)
-	entity.index = crud.index
+	entity := newEntity(atomic.AddInt32(&crud.index, 1), model, opts)
 	entity.callback = crud.callback
 	entity.callback = crud.callback
 	if len(scenarios) == 0 {
 	if len(scenarios) == 0 {
 		entity.scenarios = []string{ScenarioList, ScenarioCreate, ScenarioUpdate, ScenarioDelete, ScenarioExport, ScenarioView}
 		entity.scenarios = []string{ScenarioList, ScenarioCreate, ScenarioUpdate, ScenarioDelete, ScenarioExport, ScenarioView}

+ 3 - 2
entity.go

@@ -72,7 +72,7 @@ func (e Entities) Less(i, j int) bool {
 }
 }
 
 
 func (e Entities) Swap(i, j int) {
 func (e Entities) Swap(i, j int) {
-	e[i], e[j] = e[j], e[j]
+	e[i], e[j] = e[j], e[i]
 }
 }
 
 
 func (e *Entity) ID() string {
 func (e *Entity) ID() string {
@@ -788,8 +788,9 @@ func (e *Entity) actionMapping(ctx *http.Context) (err error) {
 	return ctx.Success(e.getMappingValue(namespace))
 	return ctx.Success(e.getMappingValue(namespace))
 }
 }
 
 
-func newEntity(model Model, opts *Options) *Entity {
+func newEntity(index int32, model Model, opts *Options) *Entity {
 	entity := &Entity{
 	entity := &Entity{
+		index:        index,
 		model:        model,
 		model:        model,
 		opts:         opts,
 		opts:         opts,
 		createdAt:    time.Now(),
 		createdAt:    time.Now(),