来自Python,我不习惯看到超过80列的代码行.所以当我遇到这个时:
err := database.QueryRow("select * from users where user_id=?", id).Scan(&ReadUser.ID, &ReadUser.Name, &ReadUser.First, &ReadUser.Last, &ReadUser.Email)
Run Code Online (Sandbox Code Playgroud)
我试图打破它
err := database.QueryRow("select * from users where user_id=?", id) \
.Scan(&ReadUser.ID, &ReadUser.Name, &ReadUser.First, &ReadUser.Last, &ReadUser.Email)
Run Code Online (Sandbox Code Playgroud)
但我明白了
syntax error: unexpected \
Run Code Online (Sandbox Code Playgroud)
我也试过打破输入并在结尾处添加分号:
err := database.QueryRow("select * from users where user_id=?", id)
.Scan(&ReadUser.ID, &ReadUser.Name, &ReadUser.First, &ReadUser.Last, &ReadUser.Email);
Run Code Online (Sandbox Code Playgroud)
但我再次得到:
syntax error: unexpected .
Run Code Online (Sandbox Code Playgroud)
所以我想知道这样做的golangic方式是什么?
我是新手去处理我想要本地化的示例代码.
在原始的main.go进口声明中它是:
import (
"log"
"net/http"
"github.com/foo/bar/myapp/common"
"github.com/foo/bar/myapp/routers"
)
Run Code Online (Sandbox Code Playgroud)
现在我已经common和routers包/home/me/go/src/myapp
所以我将import语句转换为:
import (
"log"
"net/http"
"./common"
"./routers"
)
Run Code Online (Sandbox Code Playgroud)
但是当我跑步时,go install myapp我得到了这些错误:
can't load package: /home/me/go/src/myapp/main.go:7:3: local import "./common" in non-local package
Run Code Online (Sandbox Code Playgroud)
此外,当我使用common和routers替代./common和./routers在import语句,我得到:
myapp/main.go:7:3: cannot find package "common" in any of:
/usr/local/go/src/common (from $GOROOT)
/home/me/go/src/common (from $GOPATH)
myapp/main.go:8:2: cannot find package "routers" in any of:
/usr/local/go/src/routers (from $GOROOT)
/home/me/go/src/routers (from $GOPATH)
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
我是jQuery的新手,并使用一个旧的教程node.js,使用这个片段:
$(function () {
var roomId;
$.ajax({
type: "GET",
url: "/api/rooms"
}).success(function (rooms) {
roomId = rooms[0].id;
getMessages();
$.each(rooms, function (key, room) {
var a = '<a href="#" data-room-id="' + room.id + '" class="room list-group-item">' + room.name + '</a>';
$("#rooms").append(a);
});
});
[...]
});
Run Code Online (Sandbox Code Playgroud)
但是我得到了这个错误
未捕获的TypeError:$ .ajax(...).success不是函数
在 }).success(function (rooms) {
我想知道这里有什么不对吗?
我在我的vue.js模板中有这个:
<img src="/media/avatars/{{joke.avatar}}" alt="">
Run Code Online (Sandbox Code Playgroud)
它在一个渲染笑话的循环中.Otehr字段呈现正常,但对于图像,我在控制台中收到此错误:
- src ="/ media/avatars/{{joke.avatar}}":已删除内部属性中的插值.改为使用v-bind或冒号.例如,而不是使用.
我也使用v-bind:src="...但得到invalid expression错误.
我怎样才能解决这个问题?
查询用户时遇到困难,定义如下:
type User struct {
ID int `db:"id" json:"id"`
UserName string `db:"username" json:"username"`
Email string `db:"email" json:"email"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
StatusID uint8 `db:"status_id" json:"status_id"`
Deleted uint8 `db:"deleted" json:"deleted"`
...
}
Run Code Online (Sandbox Code Playgroud)
MariaDB中的表定义为:
+--------------+------------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+------------------+------+-----+-------------------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| username | varchar(50) | NO | | NA | |
| email | varchar(255) | NO | | …Run Code Online (Sandbox Code Playgroud) 我想保存 JSON 发布的图像文件。
这是帖子的结构:
type Article struct {
Title string `json:"title"`
Body string `json:"body"`
File []byte `json:"file"`
}
Run Code Online (Sandbox Code Playgroud)
处理程序是:
func PostHandler(c *gin.Context) {
var err error
var json Article
err = c.BindJSON(&json)
if err != nil {
log.Panic(err)
}
//handle photo upload
var filename string
file, header, err := json.File //assignment count mismatch: 3 = 1
if err != nil {
fmt.Println(err)
filename = ""
} else {
data, err := ioutil.ReadAll(file)
if err != nil {
fmt.Println(err)
return
} …Run Code Online (Sandbox Code Playgroud) 当我尝试从mysql数据库中获取没有照片的文章时:
func ArticlesAllText() ([]Article, error) {
var err error
var result []Article
err = database.SQL.Select(&result, "SELECT * FROM Article WHERE photo IS NULL")
if err != nil {
log.Println(err)
}
return result, standardizeError(err)
}
Run Code Online (Sandbox Code Playgroud)
我懂了
sql:列索引10上的扫描错误:不支持的扫描,将driver.Value类型存储为* string类型
字段值为时NULL。
我怎样才能解决这个问题?
我想制作两个从中获取价值的复选框,store.js并通过表单将它们发送到后端:
<label>Notify me
<input type="checkbox" v-model="notification" value="notification" />
</label>
<label>Email me
<input type="checkbox" v-model="email" value="email" />
</label>
Run Code Online (Sandbox Code Playgroud)
我将值作为计算属性获取:
computed: {
BASE_URL () {
return this.$store.state.BASE_URL;
},
notification () {
return this.$store.state.notification;
},
email () {
return this.$store.state.email;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是检查复选框不会更改商店中的值,除此之外,我在控制台中收到此警告,如:
vue.esm.js?65d7:479 [Vue warn]: Computed property "notification" was assigned to but it has no setter.
Run Code Online (Sandbox Code Playgroud)
我知道,一个可以在计算财产定义setter方法,如描述在vue.js文档,但我不知道该怎么做,当有多个值来设置,就像在我的具体情况.
非常感谢您的帮助来解决这个问题.
我有这个v-for循环我的vue.js应用程序:
<div v-for="(word, index) in dictionary">
// break if index > 20
<p>{{word}}</p>
</div>
Run Code Online (Sandbox Code Playgroud)
我想在渲染20个单词后突破循环.我怎样才能做到这一点?我查看了文档,但没有看到任何相关内容.
在vue.js模板中,我有这个代码来删除一个笑话
<div v-on:click="delete(joke)" class="btn btn-sm">delete</div>
Run Code Online (Sandbox Code Playgroud)
以及这样做的方法:
delete: function(joke) {
console.log('delete requested');
axios.post( this.BASE_URL + "/delete" , {
id: joke.id,
token: this.token,
}).then( (res) => {
this.$router.push({ path: '/' });
})
.catch( (error) => {
console.log(error);
});
},
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
避免使用JavaScript一元运算符作为属性名称:表达式v-on中的"delete(joke)":click ="delete(joke)"
奇怪的是,在其他组件中,我joke以相同的方式将相同的对象传递给方法,并且没有错误.
我想知道这里有什么问题以及如何解决它?