找到相对于某个位置的div标签?

时间:2016-02-16 10:29:02

标签: javascript html knockout.js

我在asp.net中使用淘汰赛。我希望重用绑定到viewmodel的局部视图。即两种用法,分别绑定到不同的视图模型。

    <div class="col-xs-5" data-bind="with: vm1">
       @Html.Partial("~/Views/Shared/Customers/Modals.cshtml")
        @Html.Partial("~/Areas/Shared/Views/Lookup.cshtml")
    </div>

    <div class="col-xs-5" data-bind="with: vm2">
       @Html.Partial("~/Views/Shared/Customers/Modals.cshtml")
        @Html.Partial("~/Areas/Shared/Views/Lookup.cshtml")
    </div>

这样可以根据正确的viewmodel显示查找。

但是,在viewmodel代码中,搜索Modals中的模型div标签,然后显示模态。这导致其中一个地方出现问题,因为找到的'模态div'总是相同的(我认为第一个)。

有没有办法搜索div标签,表明我想要一些与我相关的东西?

来自后端开发人员的BR:)

1 个答案:

答案 0 :(得分:0)

您可以根据视图模型中的from t in dt.AsEnumerable() group t by t["Agent"] into newtable select new { Agent = newtable.Key; Product1 = newtable.Sum(c=>c["Product1"]); Product2 = newtable.Sum(c=>c["Product2"]); } 属性(ID或其他任何内容)为每个<tbody> <tr class="column" id="1-row"> <td> <span id="1">1</span> <a href="#1">(link)</a> </td> <td>id</td> <td>username</td> <td>sometext</td> </tr> <tr class="column" id="2-row"> <td> <span id="2">2</span> <a href="#2">(link)</a> </td> <td>name</td> <td>username</td> <td>sometext</td> </tr> </tbody> 添加唯一的<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApplication1" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*"/> <ColumnDefinition Width="1*"/> </Grid.ColumnDefinitions> <TextBox Grid.Column="0" x:Name="txtStatic" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/> <StackPanel Grid.Column="1" Focusable="False"> <Border BorderBrush="LightGray" BorderThickness="0 0 1 0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Focusable="False"> <ContentControl x:Name="con" /> </Border> </StackPanel> </Grid> </Window> 属性:

Class MainWindow

    Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
        Dim txt As New TextBox
        txt.Name = "txtDynamic"
        Me.con.Content = txt
        txt.Focus()
    End Sub

End Class

然后在你看模型:

<html>
<head>
    <title>Blablabla</title>
    <meta charset ="utf-8">
    <!-- <script type="text/javascript" src="line.js"></script> -->
</head>
<body>
    <div id="line">
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    </div>
<script type="text/javascript">
number = 5; //should be increased each time
setInterval(function(){var d = document.getElementById('line');
d.style.position = "absolute";
number++; //increase number
d.style.left = number; //move the div according to the number
}, 200); //notice that you can increase/decrease 200 according to your will

</script>
</body>
</html>