【问题标题】:Display selected VALUE from dropdown instead of the ID显示从下拉列表中选择的 VALUE 而不是 ID
【发布时间】:2011-07-22 02:26:26
【问题描述】:

我正在使用 jEditable 来允许对我的 DataTables 进行内联编辑。

我使用允许用户选择新值并将其更新回 db 的下拉菜单。

我的下拉列表由值/id 对列表组成,id 将用于链接到另一个数据库表以检索相应的值。

 public JsonResult GetFoodTypes()
    {
        // Select a list of food types as editable drop down
        var foodTypes = dbEntities.FoodTypes.ToList();
        var list = foodTypes.Select(f => new[]{f.FoodTypeID.ToString(), f.FoodTypeName.ToString()});
        return Json(list, JsonRequestBehavior.AllowGet);
    }

目前我能够在下拉列表中显示 VALUE(就我而言,是名称:例如 Fruit, Rice..etc),一旦用户提交,我将 ID 存储在表中。

我的问题是,一旦用户提交新值,我的表格的文本字段会显示 ID 而不是 VALUE。我需要刷新我的表格的页面以根据所选 ID 显示正确的 VALUE(即名称)。

知道如何让我的表格在用户提交后直接显示 VALUE 而不刷新?

【问题讨论】:

    标签: jquery asp.net-mvc-3 jeditable


    【解决方案1】:

    尝试:

    $("#your_drop_down_id").change(function () {
    
        // retrives the selected option's value
        var id = $('option:selected', this).val();
    
        // retrives the selected option's inner text
        var text = $('option:selected', this).html();
    
        // or do something else, you need, with id and/or text
        alert(id + " : " + text);
    });
    

    问候,Javad

    【讨论】:

      【解决方案2】:

      我想我在这里做类似的事情:

      callback: function (value, settings) {
                  var temp = getFoodTypeName(value);
                  //alert(temp);
                  $(this).text(temp);
              }
      

      我使用回调并将下拉字段文本设置为名称而不是ID,但我想知道这是一种非常糟糕的方式吗??

      【讨论】:

        猜你喜欢
        • 2018-11-11
        • 1970-01-01
        • 1970-01-01
        • 2013-11-09
        • 1970-01-01
        • 1970-01-01
        • 2021-10-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多