标签文字更改时

时间:2018-03-01 07:58:32

标签: jquery asp.net-mvc

  1. 我有一个标识为lblResult

  2. 的标签
  3. 我有以下代码:

          @(Html.TreeView(型号)           .EmptyContent("根&#34)           .Children(m => m.Childs)           .HtmlAttributes(new {id =" tree"})           .ChildrenHtmlAttributes(new {@class =" subItem"})           .ItemText(m => m.AssetNumber)           .ItemTemplate(                 @                     @ * @ * item.AssetNumber @                 )                 )
  4. 然后,我在视图上有以下代码:

  5. @using (Html.BeginForm("AssetTypeIndex", "ControlFiles", FormMethod.Get))
    {
    <div class="row">
    <div class="col-lg-offset-2 col-lg-8 col-lg-offset-2">
    <div class="form-inline">
    <div class="input-group">
    <span class="input-group-addon" id="basic-addon1">Search</span>
    @Html.TextBox("SearchString", ViewBag.CurrentFilter as string, new { @class = "form-control" })
    <span class="input-group-btn">
    <button class="btn btn-default" type="submit" value="Search">View</button>
    </span>
    </div>
    <div class="pull-right">
    <a href=@Url.Action("AssetTypeCreate", "ControlFiles") class="btn btn-default">Create New</a>
    </div>
    </div>
    </div>
    </div>
    }

    1. 在脚本部分:

              $(function(){             var selectedData;             $(&#39;#jstree&#39)。jstree({                 &#34;核心&#34;:{                     &#34;多个&#34;:是的,                     &#34; check_callback&#34;:是的,                     &#39;主题&#39;:{                         &#34;响应&#34;:是的,                         &#39;变种&#39;:&#39;小&#39;,                         条纹&#39;:假,                         &#39;点&#39;:真实                     }                 },                 &#34;类型&#34;:{                     &#34;默认&#34;:{                         &#34; icon&#34;:&#34; glyphicon glyphicon-record&#34;                     },                     &#34; root&#34;:{                         &#34; icon&#34;:&#34; glyphicon glyphicon-ok&#34;                     }                 },                 &#34;插件&#34;:[&#34; dnd&#34;,&#34;州&#34;,&#34;类型&#34;,&#34;排序&#34;]             })。(&#39; changed.jstree&#39;,function(e,data){                 var i,j,r = [];                 for(i = 0,j = data.selected.length; i
    2. 如果你看到上面的代码。有一个提交按钮,它触发控制器上的搜索功能。
      我的问题是,是否可以运行搜索功能&#39;没有点击按钮?我想运行搜索功能&#39;当lblResult从jsTree收到文本时,这意味着当lblResult文本发生变化时。

      请指教。
      谢谢。

2 个答案:

答案 0 :(得分:0)

Option 1: When clicking a node on your jsTree trigger that submit function by simulating a mouse-click using click method. As you know for sure the label will be changing.

@using (Html.BeginForm("AssetTypeIndex", "ControlFiles", FormMethod.Get)){
    <div class="row">
        <div class="col-lg-offset-2 col-lg-8 col-lg-offset-2" style="margin-top:-5px;">
            <div class="form-inline">
                <div class="input-group">
                    <span class="input-group-addon" id="basic-addon1">Search</span>
                    @Html.TextBox("SearchString", ViewBag.CurrentFilter as string, new { @class = "form-control" })
                    <span class="input-group-btn">
                        <button class="btn btn-default" id="submitSearch" type="submit" value="Search">View</button>
                    </span>
                </div>

                <div class="pull-right">
                    <a href=@Url.Action("AssetTypeCreate", "ControlFiles") class="btn btn-default">Create New</a>
                </div>
            </div>
        </div>
    </div>
}
$("#submitSearch").click(); // use the code when clicking a node on jsTree

Option 2: If you are manually changing the label by entering in a textbox then use the keyup event to trigger submit function.

$(function(){
  $("#lblreasult").on('keyup', function(){
    $("#submitSearch").click();
  });
});

答案 1 :(得分:0)

很抱歉我迟到了,当你点击jsTree ex中的节点时:标签的id是node1,你可以删除这段代码

<span class="input-group-btn">
     <button class="btn btn-default" id="submitSearch" type="submit" value="Search">View</button>
 </span>

或添加此css代码

#submitSearch{display:hidden}

我在你的代码中编辑了一下

$('#jstree').on('changed', function (e, data) { 
    var i, j = data.selected.length, r = []; 
    for(i = 0,  i < j; i++) { 
        r.push(data.instance.get_node(data.selected[i]).text); 
    } 
    $('#event_result').html('Selected: ' + r.join(', ')); 
    $('#lblResult').text('your text here');//
    $('form').submit();
});