将图像绑定到中继器中的图像占位符

时间:2019-07-19 09:28:37

标签: nativescript

我有一个中继器,可从SQLite加载信息并运行良好。用户可以选择同时存储在其照片库和临时文件夹中的照片。重新加载页面时,我需要将图像重新加载到转发器中相关部分下的缩略图滑动库。

图像中继器定义为

    <Repeater items="{{ images }}" id="{{ repeaterphotoid }}">
                                        <Repeater.itemTemplate>

                                <Image src="{{localurl}}" width="75" height="75" visibility="{{photoevidence === 'y' ? 'visible' : 'collapse'}}" />

                                            </Repeater.itemTemplate>
                                    </Repeater>

我的代码是

   exports.takePic = function(args){
     var page = args.object;
    camera.requestPermissions().then(
    function success(){
       var livesite = appSettings.getString("livesite");
       var images=[];
       var whichcamera = args.object;
        var options = {saveToGallery: true, keepAspectRation: true, height: 1024 };
        var gallery = args.object.page.getViewById("images-"+whichcamera.id);
        var source = new imageSourceModule.ImageSource();
        camera.takePicture(options).then(function(imageAsset){
            var img = new imageModule.Image();
            source.fromAsset(imageAsset).then((imageSource) => {
                var auditDB = new sqlite("my.db", function(err, db){
                    if (err){
                            alert("Failed to open the database", err);
                        } else {
                var tempfilename = livesite+"-"+whichcamera.qid+"-";
                db.all("SELECT filename FROM images WHERE filename LIKE '"+tempfilename+"%'").then(rows =>{
                    //console.log("Images rows="+rows.length+1);
                    if (rows.length == 0){
                        imageCount = 1;
                    }
                    else
                        {
                            imageCount = rows.length+1;
                        }
                var livesite = appSettings.getString("livesite");
               // var path = filesystem.path.join(filesystem.knownFolders.documants().path,"photos")
                var folder = filesystem.knownFolders.documents();
                var filename = livesite+"-"+whichcamera.qid+"-"+imageCount+".jpg";
                var imgPath = filesystem.path.join(folder.path,filename);
                var saved = imageSource.saveToFile(imgPath,"jpg");
                if (saved){
                            var livesite = appSettings.getString("livesite");
                            var liveaudit = appSettings.getString("liveaudit");
                            db.execSQL("INSERT INTO images (localurl,remoteurl,syncd,siteid,filename,question) VALUES(?,?,?,?,?,?)",[imgPath,'-','n',livesite,filename,whichcamera.qid])
                            var imageList = [];
                    var tempfilename = livesite+"-"+whichcamera.qid+"-";
                            var imageSQL = "SELECT localurl,remoteurl,filename FROM images WHERE filename LIKE '"+tempfilename+"%'";
                            db.all(imageSQL).then(rows =>{
                                for (var row in rows) {
                                    imageList.push({
                                        localurl: rows[row][0],
                                        filename: rows[row][2]
                                    });
                                }
                                const imagesource = fromObject({
                                images: imageList
                                    });
                                imagesource.set = ("images", imageList);
                                var imageholder = args.object.page.getViewById("repeat_"+whichcamera.id);   
                                imageholder.bindingContext = imagesource;
                            });
                            };
                });

                    };

                });
            });
        }).catch(function (err) {
            alert("Camera Error "+err.message);
        })
      //alert("Taking Pic with camera "+whichcamera.id); 
    },
        function failure(){
          alert("You must allow this app access to the camera and your photos library.")  
        });   
}

绑定问题可以按预期进行,但是我无法将图像绑定到图像中继器,什么也没发生。显然缺少了一些东西,但是使代码变得盲目。

0 个答案:

没有答案