首页 \ 问答 \ 添加
  • 从文件夹photoswipe目的动态读取(Add
  • dynamically reading from a folder photoswipe purpose)
  • 添加
  • 从文件夹photoswipe目的动态读取(Add
  • dynamically reading from a folder photoswipe purpose)
  • 对不起我的英语,我是jquery手机的新手,一般只掌握javascript语言的基本知识; 我正在玩一个单页网站移动(我通常使用Dreamweaver CS6),我用photoswipe达到了一个很好的结果,一切都很好,因为我只有几个图像。 我添加了很多它们,所以现在我会动态地获取图像的链接。

    简而言之,我想从我的ftp上的文件夹开始并读取其中的所有图像文件,并为每个文件创建<li>项目。 我可以使用jquery mobile完成这项工作,还是应该使用像php或.Net这样的语言

    我已经在这里和谷歌上阅读了一些例子,但他们并没有帮助我很多,比如这个,我相信它可能是我的答案,但我不知道如何启动http:// docs .phonegap.com / EN / 2.4.0 / cordova_file_file.md.html#DirectoryReader

    这里有一些我正在使用的代码:

    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
    
    <!-- Librerie PhotoSwipe   -->
    <link rel="stylesheet" type="text/css" href="../PhotoSwipe/photoswipe.css">
    <link rel="stylesheet" type="text/css" href="../PhotoSwipe/styles.css">
    <script type="text/javascript" src="../PhotoSwipe/klass.min.js"></script>
    <script type="text/javascript" src="../PhotoSwipe/code.photoswipe-3.0.5.min.js"></script>
    <!-- End PhotoSwipe   -->
    
        <script type="text/javascript">
    $(document).ready(function(){ var myPhotoSwipe = $("#Gallery a").photoSwipe({ enableMouseWheel: false , enableKeyboard: false, captionAndToolbarAutoHideDelay: 0 }); }); 
    </script>
    

    然后我的页面

    <div data-role="page" id="page">
        <div data-role="header">
            <h1>Title of my Page</h1>
        </div>
    
        <div data-role="content">   
        <ul id="Gallery" class="gallery">  
    
        <li>
        <a href="../Images/img04.jpg">
        <img src="../Images/img04.jpg" alt=""></a>
        </li> 
    </ul>
    </div>
    

    当我登陆这个页面时一切正常。 我要用这样的东西吗? 我从这个网站上获取,我可以使用JSON加入我的ftp文件夹而不是循环内容吗? 我应该把它放在一个功能中吗? 如果是谁将打电话给它?

    $("#Photos").live("pagebeforeshow", function(){
        $("ul#PhotoList").children().remove('li');
        var tag = MyTag
        $.getJSON("https://api.instagram.com/v1/tags/" + tag + "/media/recent?callback=?&amp;client_id=####",
        function(data){
            $.each(data.data, function(i,item){
                $("ul#PhotoList").append('<li><a href="' + item.images.low_resolution.url + ' rel="external"><img src="' + item.images.low_resolution.url + '" alt="' + item.caption.text + '" width="200" /></a></li>');
            });
        });
        var photoSwipeInstance = $("ul#PhotoList a").photoSwipe();
    });
    

    任何帮助都是适当的,谢谢你,我相信我的问题是我的有限知识。


    Sorry for my English, I am a new to jquery mobile and only have basic knowledge about javascript languages in general; I was playing around with a single page website mobile ( I usually use Dreamweaver CS6) and I reached a good result with photoswipe and everything was good since I had just few images. I have added a lot of them so now I would get the images' link dynamically.

    In short, I want to start from a folder on my ftp and read all images file within it and create the <li> items for each one. Can I make this job with jquery mobile or should I use a language like php or .Net

    I have read some examples around here and on google but they didn't help me a lot, like this one, I am sure it could be an answer for me in it but I don't know how to start http://docs.phonegap.com/en/2.4.0/cordova_file_file.md.html#DirectoryReader

    Here some code I'm using:

    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
    
    <!-- Librerie PhotoSwipe   -->
    <link rel="stylesheet" type="text/css" href="../PhotoSwipe/photoswipe.css">
    <link rel="stylesheet" type="text/css" href="../PhotoSwipe/styles.css">
    <script type="text/javascript" src="../PhotoSwipe/klass.min.js"></script>
    <script type="text/javascript" src="../PhotoSwipe/code.photoswipe-3.0.5.min.js"></script>
    <!-- End PhotoSwipe   -->
    
        <script type="text/javascript">
    $(document).ready(function(){ var myPhotoSwipe = $("#Gallery a").photoSwipe({ enableMouseWheel: false , enableKeyboard: false, captionAndToolbarAutoHideDelay: 0 }); }); 
    </script>
    

    Then my page

    <div data-role="page" id="page">
        <div data-role="header">
            <h1>Title of my Page</h1>
        </div>
    
        <div data-role="content">   
        <ul id="Gallery" class="gallery">  
    
        <li>
        <a href="../Images/img04.jpg">
        <img src="../Images/img04.jpg" alt=""></a>
        </li> 
    </ul>
    </div>
    

    When i land on this page everything works fine. Shall I use something like this? That I took from this website, can I use JSON to accede to my ftp folder and than cycle the content? Should I put this in a function? If yes who is going to call it?

    $("#Photos").live("pagebeforeshow", function(){
        $("ul#PhotoList").children().remove('li');
        var tag = MyTag
        $.getJSON("https://api.instagram.com/v1/tags/" + tag + "/media/recent?callback=?&amp;client_id=####",
        function(data){
            $.each(data.data, function(i,item){
                $("ul#PhotoList").append('<li><a href="' + item.images.low_resolution.url + ' rel="external"><img src="' + item.images.low_resolution.url + '" alt="' + item.caption.text + '" width="200" /></a></li>');
            });
        });
        var photoSwipeInstance = $("ul#PhotoList a").photoSwipe();
    });
    

    Any help is appriciated, thank you in advance, I am sure my issue here is my limited knowledge.


    原文:https://stackoverflow.com/questions/20594727
    更新时间:2022-11-05 19:11

    最满意答案

    问题在于你使用size()函数。 它重复调用文件句柄上的fgetc() ,直到它到达文件末尾,递增一个值以跟踪文件中的字节数。

    这不是一个糟糕的方法(虽然我确信有更好的方法不涉及低效的基于字符的I / O)但它确实有一个你似乎忽略的致命缺陷。

    在您调用它之后,您已经将文件一直读到最后,以便进一步读取,例如:

    fgets(color, ARR_SIZE, fp);
    

    因为你已经在文件的末尾,所以会失败。 在从size()返回之前,您可能需要考虑rewind()类的东西 - 这会将文件指针放回文件的开头,以便您可以再次读取它。


    The problem lies in your use of the size() function. It repeatedly calls fgetc() on the file handle until it gets to the end of the file, incrementing a value to track the number of bytes in the file.

    That's not a bad approach (though I'm sure there are better ones that don't involve inefficient character-based I/O) but it does have one fatal flaw that you seem to have overlooked.

    After you've called it, you've read the file all the way to the end so that any further reads, such as:

    fgets(color, ARR_SIZE, fp);
    

    will simply fail since you're already at the end of the file. You may want to consider something like rewind() before returning from size() - that will put the file pointer back to the start of the file so that you can read it again.

    相关问答

    更多
    • fileopen未初始化。 在您的情况下恰好为空,触发分段错误。 fileopen = open(filename, "r"); if (fileopen) { while (...) { } } fileopen is uninitialized. It so happens to be null in your case, triggering the segmentation fault. fileopen = open(filename, "r"); if (fileopen) { ...
    • 这个有三个问题: while (fgets(buf,1000, ptr_file)!=NULL) fscanf(buf, "%d,%d\n", &v1, &v2); fgets已经读取数据,因此fscanf不再可用 你使用%d作为格式说明符(整数),但你想读取浮点值(也改变v1和v2的类型!) fscanf的第一个参数是文件流,因此您需要在那里提供ptr_file 。 所以改成它: fscanf(ptr_file, "%f,%f", &v1, &v2); 但请注意,此文本格式可能不适用于 ...
    • $insert = "insert into $name (serial,data,used) values('','fgets($file)','0')"; 您正在将文本文本fgets($file)插入数据库,因为它嵌入在父字符串中。 你想要这样的东西,而且(顺便说一下)它也会删除sql注入漏洞: $string = fgets($file); $string = mysql_real_escape_string($string); $insert = "insert into ... value ...
    • 一旦找到token您永远不会复制token 。 你不能复制linebuffer ,因为当下一行被加载时,那里的数据将被覆盖。 这一行: number[ctr] = linebuffer; 应该引用token来保存最近找到的令牌,但事实并非如此。 它可能应该读为1 : strcpy(number[ctr], token); 但是你必须改变声明以确保空间: char number[3][32]; 显然,这会引入缓冲区溢出风险,如果有一个很长的令牌,它就不适合。 如何最好地处理这是一个练习。 :) 1为什么 ...
    • 问题在于你使用size()函数。 它重复调用文件句柄上的fgetc() ,直到它到达文件末尾,递增一个值以跟踪文件中的字节数。 这不是一个糟糕的方法(虽然我确信有更好的方法不涉及低效的基于字符的I / O)但它确实有一个你似乎忽略的致命缺陷。 在您调用它之后,您已经将文件一直读到最后,以便进一步读取,例如: fgets(color, ARR_SIZE, fp); 因为你已经在文件的末尾,所以会失败。 在从size()返回之前,您可能需要考虑rewind()类的东西 - 这会将文件指针放回文件的开头,以便您 ...
    • 那么,你可以检查两个显而易见的事情: 文件的大小( FileInfo.Length ) 最后写入时间( FileSystemInfo.LastWriteTimeUtc ) 如果你跟踪这些,你应该能够检测文件何时发生变化 - 至少在合理的置信度下。 此外,您可以使用FileSystemWatcher来监视更改。 此外,您可能需要考虑跟踪您所读取的位置 - 因此您可以通过寻找文件中的正确位置来阅读新数据。 最后, TextBox可能不是真正的巨大日志文件的最佳用户界面。 如果这是一个结构化的日志文件,那么在UI ...
    • 来自IEEE Std1800-2012§21.3.4.2一次读一行 : 可以使用$fgets从文件中读取一行。 例如: integer code; code = $fgets ( str, fd ); 将 fd指定的文件中的字符读入变量 str直到 str被填充,或者读取换行符并将其传送到 str ,或者遇到 EOF条件。 如果 str长度不是整数个字节,则不使用最重要的部分字节来确定大小。 如果从文件读取错误,则 code设置为零。 否则,读取的字符数将以 code形式返回。 应用程序可以调用 $ferr ...
    • 这里有两个问题: 混合fscanf()和fgets()是一个坏主意,因为前者在一条线上工作,后者在一条完整线上工作。 float并不像你期望的那样精确。 解决1: fscanf(donnees, "%d", &num[n]); fscanf(donnees, "%s", nom[n]); fscanf(donnees, "%s", pre[n]); fscanf(donnees, "%f\n", ¬e[n]); 为了避免溢出“字符串”,您可以告诉fscanf()以最大值扫描多少,例如,对于"%42s ...
    • Scanner类有一个构造函数Scanner(InputStream) ; 所以你仍然可以像以前一样使用这个类来读取数据。 你所要做的就是从Jar中读取文件,你可以这样做: InputStream is = getClass().getResourceAsStream("champdata.txt"); Scanner read = new Scanner(is); read.useDelimiter("%"); 如果名为champdata.txt的文件位于jar文件的根目录(这只是一个zip文件,则可以 ...

    相关文章

    更多

    最新问答

    更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)