我需要在HTML中的knockout.js的foreach循环中禁用锚标记.
这是我的代码:
<a id="aQStreamSkype" data-bind="attr:{href: ''}, click: $parent.StoreUserClick,disable: ($data.SkypeId == 'null')">Skype </a>
Run Code Online (Sandbox Code Playgroud) 我有一个带有onkeypress事件的html文本框,可以发送如下信息
<input type="text" data-bind="attr:{id: 'txtDim' + $data.userID, onkeypress: $root.sendMsg('#txtDim' + $data.userID, $data)}" />
Run Code Online (Sandbox Code Playgroud)
我已经编写了javascript函数来发送消息,同时按下面输入按钮:
self.sendMsg = function (id, data) {
$(id).keydown(function (e) {
if (e.which == 13) {
//method called to send message
//self.SendDIM(data);
}
});
};
Run Code Online (Sandbox Code Playgroud)
在我的情况下,我必须按2次输入按钮发送消息.1:按键调用self.sendMsg 2:按键调用self.SendDIM
但我只需要在一个按键上发送消息.它只能在普通的javascript中完成.但我需要viewmodel数据,因此应用于data-bind.所以不能正常工作.
我有一个复选框和单击事件,用于更新数据的复选框.当我单击复选框时,数据正在更新,但未选中复选框.
这是我的HTML代码:
<td>
<input type="checkbox" data-bind="checked: status, disable: status, click: $root.UpdateStatus" />
</td>
Run Code Online (Sandbox Code Playgroud)
这是我的脚本:
self.UpdateStatus = function (tblUsers) {
$.ajax({
type: "POST",
url: 'SinglePageApp.aspx/UpdateStatus',
data: "{statusVal: 'true',goalId: " + tblUsers.goalId + "}",
contentType: "application/json; charset=utf-8",
success: function (result) {
alert(result.d);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
alert(errorThrown);
}
});
};
Run Code Online (Sandbox Code Playgroud)
我希望我的复选框在点击时被检查.然后在点击复选框后放入更新的数据.
在我的viewModel中,我想获取当前的会话值.为此我写的是这样的:
self.currentUserId = ko.observable(HttpContext.Current.Session["UserID"]);
Run Code Online (Sandbox Code Playgroud)
但它显示我的错误
ReferenceError: HttpContext is not defined.
Run Code Online (Sandbox Code Playgroud)
如何定义HttpContext?或者有没有办法获得当前的会话值?
我是淘汰使用knockout2.1.0的新手.我有一个外部java脚本文件,但它没有在我的html文件中调用.我不明白.
我在我的html文件中添加了以下内容
<script src="Scripts/TestJavascript.js"></script>
Run Code Online (Sandbox Code Playgroud)
JS档案
///<reference path="~/Scripts/jquery-1.8.1.min.js">
///<reference path="~/Scripts/knockout-2.1.0.debug.js">
$(function AppViewModel() {
this.firstName = ko.observable("rash");
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function(){
return this.firstName() + " " + this.lastName();
}, this);
})
ko.applyBindings(new AppViewModel());
Run Code Online (Sandbox Code Playgroud)
谢谢.