我正在制作一张可分类且可调整大小的图像相册.在那里,我试图添加一个功能来创建图像作为链接.
单击图像
然后用div显示该图像,该div在该图像的顶部显示一个编辑按钮.
a tag
使用给定的URL和名称包装图像.演示 jsfiddle
还行吧.但我想做的是:
我怎样才能做到这一点?我认为unwrap()将从图像中删除编辑div,但我怎么知道它是相同的图像,还是其他的东西?
js片段:
$('#sortable li img').on("click", function () {
$image = $(this);
image_resize($image);
edit_image($image);
});
function edit_image(image) {
image.wrap('<div id="edit-image"></div>');
$('#edit-image').prepend('<a href="#">EDIT</a>');
$("#edit-image a").center(true).css("cursor", "pointer").css("z-index", "1");
$('#edit-image a').on("click", function () {
alert("clicked on edit");
if (image.parent().is("a")) {
var img_link = image.parent().attr("href");
var img_name = image.parent().attr("alt");
$('#image_link_dialog #input #link').val(img_link);
$('#image_link_dialog #input #name').val(img_name);
}
$('#image_link_dialog').css("display", "block").css("z-index", "2");
$('#image_link_dialog').center(false);
$('#image_link_dialog').draggable();
});
$('#image_link_dialog .dialog_handle a').on("click", function () {
if (!$('#image_link_dialog #input …
Run Code Online (Sandbox Code Playgroud) 我有一个TextInput,我想在我的函数中引用它.
next() {
let body = this.refs.body.value
}
<View>
<Text>Place the body here</Text>
<TextInput ref="body" placeholder="Your body goes here..." style={styles.body} placeholderTextColor='green'/>
</View>
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误:
undefined不是对象(评估'this.refs.body')
是ref
不是在本机做反应?
我有这个 Item 模型的序列化程序。
class Item(models.Model):
user = models.ForeignKey(User)
title = models.CharField(max_length=150)
body = models.TextField(blank=True)
image = models.ImageField(upload_to=get_upload_file_name, blank=True)
class ItemSerializer(serializers.ModelSerializer):
class Meta:
model = Item
fields = ('id', 'user', 'title', 'body', 'image')
def create(self, validated_data):
item = Item.objects.create(
user=self.validated_data['user'],
title=self.validated_data['title'],
body=self.validated_data['body'],
image=self.validated_data['item_image']
)
return item
Run Code Online (Sandbox Code Playgroud)
和用户序列化程序。
class CustomUserSerializer(serializers.ModelSerializer):
class Meta:
model = CustomUser
fields = (
'id', 'email', 'password', 'username', 'first_name', 'last_name',
)
extra_kwargs = {
'password': {'write_only': True},
'id': {'read_only': True}
}
def create(self, validated_data):
user = CustomUser.objects.create(
email=validated_data['email'], …
Run Code Online (Sandbox Code Playgroud)