Last active
May 27, 2017 10:02
-
-
Save giscafer/e6dfffd491de097253a54692387b7439 to your computer and use it in GitHub Desktop.
nativescript selected picture and delete picture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 删除图片 | |
* @param args | |
*/ | |
exports.onPictureDelete = function (args) { | |
var result = [], flag = false; | |
var imgId = args.object.imgId; | |
var imageItems = list_view.bindingContext.imageItems; | |
var pickImgArr = [model.UPLOAD_BTN_IMG]; | |
if (imageItems.length == signPicNumber && maxPicture) { | |
flag = true; | |
} | |
//移除元素 | |
if (imgId) { | |
imageItems.forEach(function (item, index) { | |
if (item.id == imgId) { | |
imageItems.splice(index, 1); | |
} | |
}); | |
} | |
if (flag) { | |
result = [].concat(imageItems).concat(pickImgArr); | |
maxPicture = false; | |
} else { | |
result = [].concat(imageItems) | |
} | |
list_view.bindingContext.imageItems = result | |
}; | |
/** | |
* 选择图片 | |
* @param args | |
*/ | |
exports.onPicTap = function (args) { | |
// console.log('onPicSelect'); | |
var img = args.object; | |
//如果不是上传图标点击事件 | |
if (img.src && img.src.trim() != 'res://tjtp2x') { | |
return; | |
} | |
selectPic = true; | |
var imageItems = list_view.bindingContext.imageItems; | |
var pickImgArr = [imageItems.pop()]; | |
imageUploadPicker.selectSingle(args, list_view, null, function (data) { | |
var imgData = JSON.parse(data); | |
var imageArr = imgData; | |
var result = []; | |
if (imageItems.length < (signPicNumber - 1)) { | |
result = imageItems.concat(imageArr).concat(pickImgArr) | |
} else { | |
//大于signPicNumber张时,不能上传 | |
result = imageItems.concat(imageArr); | |
maxPicture = true; | |
} | |
list_view.bindingContext.imageItems = result | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--图片信息--> | |
<FlexboxLayout alignContent="flex-start" flexWrap="wrap" cssClass="image-info"> | |
<Repeater id="list-view" items="{{ imageItems }}"> | |
<Repeater.itemsLayout> | |
<WrapLayout orientation="horizontal"/> | |
</Repeater.itemsLayout> | |
<Repeater.itemTemplate> | |
<StackLayout orientation="horizontal" class="ios_imageShow" | |
horizontalAlignment="left" id="pic_container"> | |
<AbsoluteLayout> | |
<Image src="{{url}}" imgId="{{id}}" verticalAlignment="center" class="ios_image" tap="onPicTap" | |
stretch="aspectFill" | |
height="80" width="75"/> | |
<Image src="res://san2x" imgId="{{id}}" height="15" left="60" tap="onPictureDelete" | |
visibility="{{url=='res://tjtp2x'?'collapse':'visible'}}"/> | |
</AbsoluteLayout> | |
</StackLayout> | |
</Repeater.itemTemplate> | |
</Repeater> | |
</FlexboxLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment