没有相同值的从属列表

时间:2019-05-08 18:51:12

标签: javascript html asp.net

我正在尝试使用javascript使一个列表依赖于另一个列表,但是第二个列表的值是第一个列表的值加上它自己的ID(用“ *”分隔)。我一直在尝试拆分值并仅获取第一部分,但它什么也没有返回。代码有什么问题?

listaversao = _context.Versao.Select(v => new SelectListItem
{
   Value = v.idLinguagem.ToString() + "*" + v.idVersao.ToString(),
   Text = v.nmVersao //this one depends on listaling, but it has two ids separated by the *;
});

listaling = _context.Linguagem.Select(l => new SelectListItem
{
  Value = l.idLinguagem.ToString(),
  Text = l.nmLinguagem
});

Javascript:

    var $linguagem = $('#lingua'), 
    $versao = $('#versao'),
    $options = $versao.find('option');

$linguagem.change(function () {
    $('#versao option')
        .hide() // hide all
        .filter(versao => versao.val().split("*")[0] == $linguagem.val()) // splits the val and filter options with required value
        .show(); // and show them
});

这就是我设置绑定的方式:


public IEnumerable<SelectListItem> listaversao { get; set; }
public IEnumerable<SelectListItem> listaling { get; set; }
[BindProperty(SupportsGet =true)]
public string[] selecaover { get; set; }

还有html:

<label asp-for="Scripts.idLinguagem" class="control-label"></label>
<br />
<select onchange="mudar()" id="lingua" asp-for="linguagem" asp-items="Model.listaling"></select>
<select id="versa" size="10" onclick="mostrarv()" multiple="multiple" asp-for="selecaover" asp-items="Model.listaversao"></select>

感谢您的帮助。

0 个答案:

没有答案