2

我有这样的代码

var databaseViewModel = new function () {
    var self = this;
    self.databaseList = ko.observable("");
    self.id = ko.observable("");
    self.databaseSelected = ko.observable("");
    self.description = ko.observable("description");

    self.openList = function () {
        alert("openList");
    };
}

html:</p>

<div data-bind="foreach: databaseList">
                <li><a href="javascript:void(0)" data-bind="click:'databaseViewModel.openList(this)',  attr: {   title: DataBaseName }">
                    <span class="pic1"></span><span data-bind="text:DataBaseName"></span></a></li>
                <div data-bind="attr: { 'data-something': DataBaseName }">
                    ...</div>
            </div>

我想点击链接DataBaseName时调用openlist,如何修改代码?</p>

4

1 回答 1

4

你想做data-bind="click: $parent.openList"

查看这些文档以获取有关$parent您可以使用的其他特殊变量的更多信息:http: //knockoutjs.com/documentation/binding-context.html

于 2013-01-07T03:51:15.193 回答