循环遍历由oracle过程生成的json列表

时间:2015-05-29 11:40:40

标签: jquery

我正在尝试在oracle过程生成的json列表上运行循环:

控制:

public static GetLovListModel GetDivCount()
{
    var p = new OracleDynamicParameters();
    p.Add("p_output", dbType: OracleDbType.RefCursor, direction: ParameterDirection.Output);
    string spName = "p_get_div_count";
    GetLovListModel glist = new GetLovListModel();
    using (var grid = DB.GetMultiGrid(spName, p: p))
    {
        glist.GetDivCount = grid.Read<GetDivCount>().ToList();
    }
    return glist;
}

型号:

$.ajax(
{
    url: '@Url.Action("GetLOVDivCount")',
    type: 'GET',
    datatype: 'json',
    success: function (result) {
        **jQuery.each(result, function(key,val){
            $("#tDivCount").last().append("<tr><td>" + result + "</td><td>New row</td><td>New row</td></tr>");**
        })
    }
});

查看:

/**
 * Return a google Calendar object for interacting with the calendar API.
 * Return null if it can't be built for any reason
 */
private Calendar buildGoogleCalendarService() throws GeneralSecurityException, IOException {
    String googleUsername = this.getGoogleUsername();
    if (googleUsername == null) {
        return null;
    }
    String path = AuthManager.class.getClassLoader().getResource("").getPath();
    File privateKey = new File(path + "/google_key.p12");
    if (!privateKey.exists()) {
        logger.error("Google private key not found at " + privateKey.getAbsolutePath());
        return null;
    }
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
            .setJsonFactory(jsonFactory).setServiceAccountId(AppProperties.googleAppEmailAddress)
            .setServiceAccountPrivateKeyFromP12File(privateKey)
            .setServiceAccountScopes(Collections.singleton(CalendarScopes.CALENDAR))
            .setServiceAccountUser(googleUsername).build();
    Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credential)
            .setApplicationName(AppProperties.appName).build();
    return service;
}

但该表只显示空数据?

2 个答案:

答案 0 :(得分:0)

删除last()

$("#tDivCount").append("<tr><td>" + val+ "</td><td>New row</td><td>New row</td></tr>")

注意:删除选择器中的last()并检查控制台中的结果值..它将打印什么,结果是一个不要放置的数组直接,在追加时使用值或键

答案 1 :(得分:0)

我找到答案:)首先我应该用结果result.GetDivCount指定模型名称

显示值:val [&#39; DivCount&#39;]

&#13;
&#13;
  success: function (result) {
                 DivJason = result;
                 jQuery.each(result.GetDivCount, function (i, val) {
                     $("#tDivCount").last().append("<tr><td>" + val['DivDesc'] + "</td><td>" + val['DivCount'] + "</td><td>New row</td></tr>");
                 })
             }
&#13;
&#13;
&#13;

感谢您的帮助。