小编Zac*_*ner的帖子

我们如何动态分配和增长数组

我正在研究一个项目,但我不能使用任何现有的java数据结构(即ArraysList,树等)

我只能使用数组.因此,我需要使用新内存动态更新数组.

我正在读取文本文件,并为阵列内存预先分配100:

   String [] wordList;
   int wordCount = 0;
   int occurrence = 1;
   int arraySize = 100;
   wordList = new String[arraySize];
   while ((strLine = br.readLine()) != null)   {
         // Store the content into an array
         Scanner s = new Scanner(strLine);
         while(s.hasNext()) {
           wordList[wordCount] = s.next();
           wordCount++;
         } 
   }
Run Code Online (Sandbox Code Playgroud)

现在这适用于100个以下列表项.br.readline是遍历文本文件每一行的缓冲读取器.我有它然后将每个单词存储到列表中,然后递增我的索引(wordCount).

但是,一旦我有一个包含超过100个项目的文本文件,我就会收到分配错误.

如何动态更新此阵列(从而重新发明轮子)?

谢谢!

java arrays word-count

9
推荐指数
2
解决办法
10万
查看次数

使用PHP中的Facebook Graph API进行教育

我正在尝试使用stdclass从Facebook的图形API获取教育信息.这是阵列:

 "username": "blah",
   "education": [
      {
         "school": {
            "id": "[removed]",
            "name": "[removed]"
         },
         "year": {
            "id": "[removed]",
            "name": "[removed]"
         },
         "type": "High School"
      },
      {
         "school": {
            "id": "[removed]",
            "name": "[removed]"
         },
         "year": {
            "id": "[removed]",
            "name": "[removed]"
         },
         "type": "College"
      }
   ],
Run Code Online (Sandbox Code Playgroud)

如何使用PHP选择类型为"college"的PHP?这是我用来阅读它的内容:

 $token_url = "https://graph.facebook.com/oauth/access_token?"
   . "client_id=[removed]&redirect_uri=[removed]&client_secret=[removed]&code=".$_GET['code']."";


 $response = file_get_contents($token_url);


 parse_str($response);

 $graph_url = "https://graph.facebook.com/me?access_token=" 
   . $access_token;


     $user = json_decode(file_get_contents($graph_url));
Run Code Online (Sandbox Code Playgroud)

所以这个名字就是$ user-> name.

我尝试了$ user-> education-> school但是没有用.

任何帮助,将不胜感激.

谢谢!

php arrays facebook-graph-api

6
推荐指数
1
解决办法
6205
查看次数

如何删除特定的textarea字段?

我有一个基于javascript生成的动态表单.这是相关的javascript:

function addRowToTable()
{ 

  var tbl = document.getElementById('convention');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);


 // right cell
  var cellRight = row.insertCell(0);

  var el = document.createElement('textarea');
  el.rows = '2';
  el.cols = '80';
  el.name = 'conventionSkill' + iteration;
  el.size = 40;

    var el2 = document.createElement('input');
  el2.type = 'hidden';
  el2.name = 'conventioni_alt';
  el2.value = iteration;
  el2.size = 40;


  el.onkeypress = keyPressTest;
  cellRight.appendChild(el); …
Run Code Online (Sandbox Code Playgroud)

javascript

1
推荐指数
1
解决办法
957
查看次数

为什么我的ajax AutoSave不能工作?

我正在使用此页面上的脚本:http://jetlogs.org/2007/11/11/auto-saving-with-jquery/自动保存我的表单.我只是想为表格保存textarea.这是相关的代码:

<head>
    <script type="text/javascript">
        $(document).ready(function(){           
            autosave();
        });

        function autosave()
        {
            var t = setTimeout("autosave()", 5000);

            var comments = $("#comments").val();

            if (comments.length > 0)
            {
                $.ajax(
                {
                    type: "POST",
                    url: "autosave.php",
                    data: "rubric_id=" + <?php echo $rubricid ?> + "&student_id=" + <?php echo $studentid ?> + "&comments=" + comments,
                    cache: false,
                    success: function(message)
                    {   
                        $("#autosave_status").empty().append(message);
                    }
                });
            }
        } 
        </script> 
</head>
<body>
<div id="autosave_status"></div>
<form action='assess.php?student=146&rubric=19' method='POST'>
<textarea id="elm1" name="comments" rows="15" cols="80" style="width: 80%">
</form>
</body>
Run Code Online (Sandbox Code Playgroud)

这是PHP: …

javascript php ajax jquery

0
推荐指数
1
解决办法
331
查看次数

如何在dompdf 6.0 beta 2中做一个页脚?

在最近的dompdf版本(domdpf beta 2)中,出于安全原因,内联php被禁用.这反过来导致了之前的页脚/标题代码:

<script type="text/php">

if ( isset($pdf) ) {

  $font = Font_Metrics::get_font("helvetica", "bold");
  $pdf->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));

}
</script>
Run Code Online (Sandbox Code Playgroud)

不再工作了.

我现在正在尝试使用CSS重新创建此脚本所执行的操作.到目前为止,我已经弄清楚如何让CSS计算页面:

.pagenum:before { content: counter(page); }
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是将页脚粘贴到页面底部.关于如何执行此操作的大多数CSS教程似乎都不起作用.这是我的页面的CSS:

html,body {
     font-family:interstate;
    height:100%;
    width:100%;
    overflow:auto;
    margin-left: 40px;
    margin-right: 40px;
    margin-top: 20px;   
 margin-bottom:40px;
 min-height: 100%;
}



P.breakhere {page-break-before: always}

table
{
  border-collapse: collapse;
    page-break-inside: avoid;
  font-size:15px;

    }

td
{
border: 1px solid #000

}
.noBorder {
    border: 0
}


#header {background:#ffffff url('gradient.png') no-repeat center center;
height: 100px; …
Run Code Online (Sandbox Code Playgroud)

css dompdf

0
推荐指数
1
解决办法
7055
查看次数

在事件期间暂停setInterval?

我有一个秒表功能,可以通过开始/停止按钮切换.按下停止按钮时,计时器停止,jQuery将一行插入预先加载到页面上的表中.

我在后台运行另一个jQuery脚本,不断更新该表以维护新数据.它本质上是一个计时员.

但是,我遇到的问题是当用户按下停止按钮时,setInterval加载继续运行,导致添加的jquery字段消失.

我已经尝试添加一个变量来检查停止按钮是否被按下,如果是,则停止事件...但由于它已经加载到DOM中,它似乎不起作用.这是当前的代码:

            $.ajax({
                url: 'getData.php',
                success: function(data) {
                    $("#timesheet").html(data);
                }
            });

            var refreshId = setInterval(function() {
                $.ajax({
                    url: 'getData.php?randval='+ Math.random(),
                    success: function(data) {
                        $("#timesheet").html(data);
                    }
                });
            }, 9000);
Run Code Online (Sandbox Code Playgroud)

这是ajax加载的HTML数据:

<table>
<tr><th>Test</th></tr>
<tr><td>Test</td></tr>
</table>
Run Code Online (Sandbox Code Playgroud)

我也试过在tr:last上使用append,但是只是将它附加到tr ...而不是创建一个新的tr.

TL; DR:我希望setInterval不会覆盖按下按钮时jQuery添加的字段,但似乎不能这样做,因为它被编码以更改整个表.

谢谢你的任何建议.

javascript jquery

0
推荐指数
1
解决办法
176
查看次数

标签 统计

javascript ×3

arrays ×2

jquery ×2

php ×2

ajax ×1

css ×1

dompdf ×1

facebook-graph-api ×1

java ×1

word-count ×1