dataUrl(selectoptions for select)无法将数据填充/填充到JQGRID中的Dropdownlist中

时间:2016-02-24 16:51:29

标签: jquery jqgrid asp.net-ajax free-jqgrid

我正在使用JQGRID和代码如下

 <script src=”Scripts/jquery-1.11.0.min.js” type=”text/javascript”></script>
 <script src=”Scripts/grid.locale-en.js” type=”text/javascript”></script>
 <script src=”Scripts/jquery.jqGrid.min.js” type=”text/javascript”></script>
 <script src=”Scripts/jquery-ui.min.js” type=”text/javascript”></script>

使用以下参考文件..

<Select>

我能够加载数据并将其从JQGRID保存到SQL数据库,反之亦然。 但是,选择选项(列:门)没有加载任何数据..我试图调试代码并理解dataUrl在编辑行期间没有通过内联导航触发。

函数BindDDInfo背后的代码(返回类型为&#39;字符串&#39;并提到Webmethod和static)以<Option>……</Option> </Select> <select> <option value='1'>Text1</option> <option value='2'>Test2</option> <option value='3'>Test3</option> <option value='4'>TEst5</option> <option value='5'>TEst6</option> <option value='6'>Test7</option> <option value='7'>Test8</option> <option value='8'>Test9</option> </select> 格式返回字符串。

Response         HTTP/1.1 200 OK
Server           ASP.NET Development Server/10.0.0.0
Date             Wed, 24 Feb 2016 15:07:16 GMT
X-AspNet-Version 4.0.30319
Cache-Control    no-cache, no-store
Pragma           no-cache
Expires          -1
Content-Type     text/html; charset=utf-8
Content-Length   69186
Connection       Close

通过F12检查(在IE9中),可以看到响应标题如下

        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

响应正文返回data.aspx html页面,不知道出了什么问题。

然后,我在web.config文件中添加了HTTP处理程序

List<Dictionary<string, object>>

现在,dataUrl正在点击webmethod BindDdInfo并弹出警报(&#34; hello&#34;)(来自ajaxSelectOptions),但它不会在editoptions中进行buildSelect。

以下作为回复者返回       {&#34; d&#34;:&#34; \ u003cselect \ u003e \ u003coption value = \ u00271 \ u003eTest1 \ u003c / option \ u003e \ u003c / select \ u003e&#34;}

在建议从BindDDInfo获取JSOn数据之后,我修改了以下代码,

我已经更改了我的webmethod以返回ajaxSelectOptions: { type: ‘POST’, contentType: ‘application/json; charset=utf-8’, datatype: ‘json’, success: function (result) { alert(JSON.stringify(result)); } } 和以下代码

  {“d”:[{“ID”:1,”Name”:”Test1″},{“ID”:2,”Name”:”Test2″}]}

警报显示如下

 dataUrl: “Data.aspx/BindDDInfo”,
 buildSelect: function (response) {
 var data = typeof response === “string” ? JSON.stringify(response) :      response,
 s = “<select>”;
 s += ‘<option value=”0″>–Select–</option>’;
 $.each(data, function () {
 s += ‘<option value=”‘ + this.ID + ‘”>’ + this.Name + ‘</option>’;
 });
 return s + “</select>”;
 }

但是,buildSelect没有被击中,

private static Credential authorize() throws Exception 
   {
   HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
   JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
   List<String> scopes = Arrays.asList(BloggerScopes.BLOGGER);

   // load client secrets
  GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(new FileInputStream(clientId_File)));

  // set up authorization code flow
  GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
     httpTransport, jsonFactory, clientSecrets, scopes).build();

 // authorize
  return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
  }

protected void doTest2() throws Exception 
    {
    // Configure the Installed App OAuth2 flow.
    Credential credential = authorize();

    Blogger blogger = new Blogger.Builder(httpTransport, jsonFactory, credential).setApplicationName(APP_NAME).setHttpRequestInitializer(credential)
            .build();

    // The request action object.
    GetByUrl blogGetByUrlAction = blogger.blogs().getByUrl(BLOG_URL);

    // Configure which blog URL to look up.
    blogGetByUrlAction.setUrl(BLOG_URL);

    // Restrict the result content to just the data we need.
    blogGetByUrlAction.setFields("description,name,posts/totalItems,updated");

    // This step sends the request to the server.
    Blog blog = blogGetByUrlAction.execute();

    // Now we can navigate the response.
    System.out.println("Name: " + blog.getName());
    System.out.println("Description: " + blog.getDescription());
    System.out.println("Post Count: " + blog.getPosts().getTotalItems());
    System.out.println("Last Updated: " + blog.getUpdated());
}

在buildSelect中尝试了console.log(响应)和alert(响应),但它没有给出任何弹出窗口。

任何人都可以帮助我将数据从数据库中的JQGRID中下载到下拉列表中。

1 个答案:

答案 0 :(得分:1)

您的主要问题是“dataUrl在编辑行期间未通过inlineNav触发”。我在代码中看到许多可以改进的小东西。我想主要的问题是列Name(门列)中的输入错误。你应该使用

formatter: "select"

而不是

foramtter: "Select"

(应使用formatter代替foramtter"select"代替"Select"两个错误:

此外,我会向您推荐一些其他小技巧:

  • 从您网页的HTML标记中移除<div id="jqGridDelPager"></div>,然后使用pager: true代替pager: "#jqGridDelPager"。您可以跳过 "#jqGridDelPager" navGridinlineNav参数。免费jqGrid自动为寻呼机创建了div,navGridinlineNav将使用寻呼机。
  • 您在所有列中使用label属性,在colName使用其他文本。该选项的正确名称为colNames,而不是colName。您可以将文本从label移至colNames数组,也可以删除不需要的colName数组。
  • inlineNav free jqGrid方法会自动创建导航条,它不存在。因此,您可以删除不需要的navGrid
  • 来电
  • 您无需使用ajaxSelectOptions: { cache: false, type: 'POST' }。您可以改为使用ajaxSelectOptions: { type: 'POST' }
  • 如果您希望第二次点击该行而不取消选择,则可以使用singleSelectClickMode: "selectonly"
  • 您可以使用forceClientSorting: true选项强制对客户端大小的服务器返回的数据进行排序。您只需要添加例如sortname: "Name"选项,该选项通知jqGrid数据应该排序到哪一列。
  • jsonReader的值可以减少为jsonReader: {root: "d", repeatitems: false, id: "QGDelId"}。设置id: "QGDelId"意味着每个数据项都包含具有唯一值的QGDelId属性,这应该用作rowid,这一点很重要。
  • 我不理解您使用的onSelectRow的含义以及lastSelQGDel变量的目标。我建议你删除回击。
  • free jqGrid为指定底层方法的选项提供了更舒适的方式。例如,jqGrid的inlineEditing选项允许指定内联编辑方法使用的 common 选项。您更正了代码,例如,在addParams.addRowParamseditParams中指定相同的选项(请参阅inlineNav的选项)。顺便说一句,key: trueaddParams内而不是addParams.addRowParams的位置是错误的。在jqGrid的inlineEditing选项中指定常用选项要好得多。有关详细信息,请参阅the wiki article
  • 我建议您使用
$("#jqGridDel").trigger('reloadGrid', [{fromServer: true}]);

而不是

$("#jqGridDel").jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
相关问题