我无法绑定knockout js viewmodel

时间:2017-03-03 19:24:29

标签: c# jquery html json knockout.js

说到JavaScript,我觉得很难吞下去。我一直在尝试将数据从后端绑定到客户端,但我没有成功。我认为是时候让别人向我展示我的错误了。这是代码。

$(".tab a").click(function (e) {
var url = "";
var data = "";
var Item = "";
var test = $(e.target).text();
if(test === '#') {
    var url = "#";
} 
else if (test === '#') {
    var url = "#";
} else if (test === '#') {
    var url = '#';
} else if (test === '#') {
    url = '#';
}
else {
    throw new Error('hello');
}


function userViewmodel() {

    var self = this;

     
    self.Id = ko.observable("");
    self.Link = ko.observable("");
    self.Image = ko.observable("");
    self.Title = ko.observable("");
    self.Ajax = ko.observable("");




    getUserInfo();

    function getUserInfo() {

             $.getJSON("../../Home/tabcontent?=" + url)
            .done(function (data) {


                self.Id(data.id);
                self.Link(data.link);
                self.Image(data.image);
                self.Title(data.title);
                self.Ajax(data.ajax);


            });
    }

};

ko.applyBindings(new userViewmodel());


});

我想绑定到这个。

 <div class="row col s12" style="margin-top:18px;" id="test-swipe-1">

            @foreach (var item in Model)
            {

                <div class="col s12 m6 l3">
                    <div class="card z-depth-4">
                        <div class="card-image waves-effect waves-block waves-light" style="height:350px">
                            <a href="@Url.Action("Movie", "Home", new {id= @item.id, title= @item.title})">
                                <img class="activat" src="@item.image">
                            </a>
                        </div>
                        <div class="card-content blue-grey darken-4">
                            <span class="card-title activator grey-text text-darken-1"><a class="a-title truncate" style="color:inherit">@item.title</a><i class="material-icons right" onclick="loadDoc('@item.id', '@item.ajax')">more_vert</i></span>
                            <p><a href="#" >Report broken link</a></p>
                        </div>
                        <div class="card-reveal blue-grey darken-4">
                            <span class="card-title grey-text text-darken-1 title-wrap">@item.title<i class="material-icons right">close</i></span>
                            <div id="@item.id"></div>
                        </div>
                    </div>
                </div>
            }
        </div>

我知道它在剃刀视图中,我就这样离开了,所以你可以理解我希望如何格式化数据。 请问如何将数据绑定到html标签?

0 个答案:

没有答案