我对Knockout很新,我在验证表单时遇到了一些问题.
HTML
<input data-bind="value: naam" type="text" name="naam" id="naam" placeholder="Naam" required />
<input data-bind="value: email" type="email" name="email" id="email" placeholder="E-mail" required pattern="@" />
Run Code Online (Sandbox Code Playgroud)
昏死
var OrderInfo = function(){
var self = this;
self.naam = ko.observable().extend({
required: "true",
minLength: 6
});
self.email = ko.observable().extend({
required: "true",
email: {
message: "Gelieve een geldig e-mail adres op te geven.",
params: true
}
});
};
Run Code Online (Sandbox Code Playgroud)
问题
1)当我在"naam"输入少于6个字符时,我收到消息Please enter at least 6 characters..然而,课程valid是给予元素的.电子邮件输入字段按原样获取错误类.
2)当我记录OrderInfo是否有效时,即使收到错误消息,我也总是如此;
self.OrderInfo = ko.validatedObservable(self.orderInfo);
console.log("Valid: " + self.OrderInfo.isValid());
Run Code Online (Sandbox Code Playgroud)
我已经像这样配置了ko.validation;
ko.validation.configure({ …Run Code Online (Sandbox Code Playgroud) 我有一个TextBlockWPF应用程序.
的(Text,Width,Height,TextWrapping,FontSize,FontWeight,FontFamily的这个)性质TextBlock是动态的(由用户在运行时输入).
每次用户更改以前的某个属性时,都会在运行时更改其Content属性TextBlock.(一切都好,直到这里)
现在,我需要TextBlock根据之前指定的属性获取该行.
这意味着我需要TextWrapping算法将产生的线条.
换句话说,我需要在一个单独的字符串中的每一行,或者我需要一个带Scape序列的字符串\n.
有什么想法吗?
我有以下代码,我想将post请求的授权设置为:
Authorization:key=somevalue
using (HttpClient client = new HttpClient())
{
using (StringContent jsonContent = new StringContent(json))
{
jsonContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
using (HttpResponseMessage response = await client.PostAsync("https://android.googleapis.com/gcm/send", jsonContent))
{
var reponseString = await response.Content.ReadAsStringAsync();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这该怎么做?我真的很挣扎以及以下声明
client.DefaultRequestHeaders.Add("Authorization", "key=" + apiKey);
Run Code Online (Sandbox Code Playgroud)
抛出以下异常
System.Net.Http.dll中出现"System.FormatException"类型的异常,但未在用户代码中处理
我正在研究MVC 4项目.
我有一个在Ajax Post请求完成时执行的Action.
在某些情况下,我可以确切地确定,我必须Status将Response对象的属性设置为HttpBadRequestvalue,并返回包含一些数据的JSON对象以显示给最终用户.
问题是我无法在javascript方法中收到JSON对象,我正在接收其他内容.这是因为我将Response的Status属性设置为HttpBadRequest值.
这是细节
行动
// this method will executed when some Ajax Post request.
[HttpPost]
public ActionResult Delete(int id)
{
// some code here ......
// in some case we will determine an error like this
if(error)
{
HttpContext.Response.Clear();
HttpContext.Response.TrySkipIisCustomErrors = true;
HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Json(new
{
Message = string.Format(format, values),
Status = messageType.ToString()
});
}
}
Run Code Online (Sandbox Code Playgroud)
我想从这样的javascript函数中读取这个返回的JSON对象
使用Javascript
function OnDeleteFailed(data) {
debugger;
var try1 = $.parseJSON(data.responseText);
var try2 …Run Code Online (Sandbox Code Playgroud) 我是淘汰赛的新手,并试图让我的select2与我的淘汰赛绑定很好地配合.
我想要做的就是将帐户数组绑定到我的select2(这个工作),然后在绑定发生时设置初始值.我出于某种原因不能让这个工作.还注意到init和update函数最初被调用,但是只要我更改select2下拉列表的值,就不会触发更新函数.
任何帮助,将不胜感激.
HTML
<div class="col-sm-12 col-md-3">
<fieldset class="form-group">
<label data-bind="attr:{for:'job'+laborDetailId()}">Job</label>
<select class="select2" data-bind="attr:{id:'job'+laborDetailId()},updateaccountdropdown: {value:account(),data:accounts,width:'100%'}">
</select>
</fieldset>
</div>
Run Code Online (Sandbox Code Playgroud)
JS
var accounts = [{"id":-1,"text":"","description":null}, {"id":25,"text":"J13002","description":null}, {"id":28,"text":"J13053","description":null}];
var LaborListModel = function(laborModels) {
var self = this;
//contains all labor models
self.labordetails = ko.observableArray(laborModels);
self.selectedAccount = ko.observable();
//bindings
ko.bindingHandlers.updateaccountdropdown = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$(element).select2('destroy');
});
var allBindings = allBindingsAccessor(),
select2 = ko.utils.unwrapObservable(allBindings.updateaccountdropdown);
$(element).select2(select2);
},
update: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var allBindings = allBindingsAccessor(); …Run Code Online (Sandbox Code Playgroud) 我有一个问题如何调用onchanges敲js到我的选择选项,我已经有一个函数和HTML,但当我选择选择选项,没有任何变化
<select data-bind="event:{change:setSelectedStation() },
options: seedData,
optionsText: 'text',
optionsValue: 'value'">
</select>
Run Code Online (Sandbox Code Playgroud)
这是我的功能
setSelectedStation: function(element, KioskId){
this.getPopUp().closeModal();
$('.selected-station').html(element);
$('[name="popstation_detail"]').val(element);
$('[name="popstation_address"]').val(KioskId);
$('[name="popstation_text"]').val(element);
// console.log($('[name="popstation_text"]').val());
this.isSelectedStationVisible(true);
},
Run Code Online (Sandbox Code Playgroud) 我想覆盖jquery validate插件的"数字"验证.
这部分:
// http://docs.jquery.com/Plugins/Validation/Methods/number
number: function(value, element) {
return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);
},
Run Code Online (Sandbox Code Playgroud)
我做了一些搜索,但我能找到的只是如何覆盖消息(我已经完成了)以及如何克服核心jQuery功能,这使我指向了这个方向......
$.fn.validate.prototype.methods.number = function (value, element) {
return this.optional(element) || /^-?\d+(?:\,\d+)?$/.test(value);
};
Run Code Online (Sandbox Code Playgroud)
使用此代码,我收到以下错误:
$ .fn.validate.prototype.methods未定义
我错过了什么吗?还是我想做不可能的事?
如果这是不可能的,建议使用另一种方法来更改此功能,而不必将自定义验证器添加到我的应用程序中的每个数字字段,这将是非常受欢迎的!
谢谢!
我有FixedDocument页面,我想TextBlock放在它上面,但它可能Textblock不适合页面的高度。
所以我想从繁重的产生线TextBlock带TextWrapping,然后创建新的TextBlock,即通过安装高度,并把它页。
TextBlock有LineCount私有财产,这意味着它TextLines在包装后有,我可以以某种方式得到它。使用运行
创建TextBlock:
public TextItem(PageType pageType, Run[] runs, Typeface typeFace, double fontSize)
: base(pageType)
{
this.TextBlock = new TextBlock();
this.TextBlock.Inlines.AddRange(runs);
if (typeFace != null)
this.TextBlock.FontFamily = typeFace.FontFamily;
if (fontSize > 0)
this.TextBlock.FontSize = fontSize;
this.TextBlock.TextWrapping = TextWrapping.Wrap; //wrapping
}
Run Code Online (Sandbox Code Playgroud)
TextBlock用文本创建:
public TextItem(PageType pageType, String text, Typeface typeFace, double fontSize)
: base(pageType)
{
if (typeFace == null || fontSize == …Run Code Online (Sandbox Code Playgroud) 我正在使用Globalize jQuery插件在MVC网站的客户端上进行全球化(正确的数字和日期格式)。因此,我已经下载了该插件,并在验证js文件本身之后添加了以下javascript文件(我也曾尝试将Globalize文件放在前面,但没有任何运气):
<script src="/Scripts/globalize.js"></script>
<script src="/Scripts/jquery.validate.globalize.min.js"></script>
<script src="/Scripts/globalize/globalize.culture.da-DK.js"></script>
Run Code Online (Sandbox Code Playgroud)
但是当运行应用程序时,我得到了错误
Globalize.addCultureInfo不是函数
我不知道是什么原因
我正在连接到mqtt,但收到一个无用的异常。
码
string smsTopic = ConfigurationManager.AppSettings["MQTT_SMS_Topic"];
string emailTopic = ConfigurationManager.AppSettings["MQTT_Email_Topic"];
string pushTopic = ConfigurationManager.AppSettings["MQTT_PUSH_Topic"];
string socialTopic = ConfigurationManager.AppSettings["MQTT_SOCIAL_Topic"];
client = new MqttClient("somehostname");
string clientId = Guid.NewGuid().ToString();
client.Connect(clientId);
client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
client.Subscribe(new string[] { smsTopic, emailTopic, pushTopic, socialTopic }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
Run Code Online (Sandbox Code Playgroud)
异常消息
引发了类型为'uPLibrary.Networking.M2Mqtt.Exceptions.MqttClientException'的异常
异常的堆栈跟踪
at uPLibrary.Networking.M2Mqtt.Messages.MqttMsgSubscribe.GetBytes(Byte protocolVersion) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\Messages\MqttMsgSubscribe.cs:line 187
at uPLibrary.Networking.M2Mqtt.MqttClient.Send(MqttMsgBase msg) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:line 1028
at uPLibrary.Networking.M2Mqtt.MqttClient.ProcessInflightThread() in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:line 1954
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, …Run Code Online (Sandbox Code Playgroud) c# ×4
javascript ×3
jquery ×3
knockout.js ×3
textblock ×2
validation ×2
wpf ×2
asp.net-mvc ×1
bad-request ×1
httpclient ×1
httpcontent ×1
json ×1
line-count ×1
magento2 ×1
mqtt ×1
onselect ×1
overriding ×1
plugins ×1
select2 ×1
word-wrap ×1