使用var query检索多行文本

时间:2018-03-20 12:46:41

标签: javascript variables

我目前有一个JS文件,显示用户通过SharePoint列表输入的单行知道问题。它在页面上显示的div id是'knowntitle'。

我现在被要求显示更多信息,以便用户可以在SharePoint列表中填写另一个字段,名为Further Details,这将是多行文本字段。

一年前我写了原始页面,我有点生疏了!我已经开始并评论了到目前为止我所做的一切。我们将非常感激地提供有关如何进行的任何帮助,如下所示:

function getDeviceKnownIssues() {

  //var txtfurtherinfo = "";
  var txtTitleKnown = "<ol>";

  var query = "http://xxx/sites/it/ITInfrastructure/_vti_bin/listdata.svc//Knownissues?$filter=DeviceID eq " + window.DeviceId + "";

  var call = $.ajax({
    url: query,
    type: "GET",
    dataType: "json",
    headers: {
      Accept: "application/json;odata=verbose"
    }
  });
  call.done(function(data, textStatus, jqXHR) {
    $.each(data.d.results, function(index, item) {
      var KnownTitle = item.Title;
      //var FurtherInfo = item.Info;
      txtTitleKnown = txtTitleKnown + "<li>" + KnownTitle + "</li>";
    });

    txtTitleKnown = txtTitleKnown + "</ol>";
    //$('furtherinfo').append(txtName);
    $('#knowntitle').append(txtTitleKnown);

  });
  call.fail(function(jqXHR, textStatus, errorThrown) {
    alert("Error retrieving data: " + jqXHR.responseText);
  });

}

1 个答案:

答案 0 :(得分:0)

您可以将更多信息与换行符\r\n连接在一起,然后将它们显示在单元格中:

$.each(data.d.results, function(index, item) {
  txtTitleKnown += "<li>" + item.Title + "</li>";
  if(item.Info != undefined) {
      txtfurtherinfo += item.Info + "\r\n";
  }
});

txtTitleKnown = txtTitleKnown + "</ol>";
$('#knowntitle').append(txtTitleKnown);
$('#furtherinfo').append(txtfurtherinfo);