淘汰赛JS-如何为可观察字段返回空字符串 [英] Knockout JS - How to return empty strings for observable fields
问题描述
我正在构建一个CRUD系统,用户可以在其中添加,删除和编辑简单表中的数据.我有一个模式表单,用于显示其他详细信息并添加新事件.当前,模态表单可以正确加载以进行编辑,但是在尝试添加新事件时会遇到问题.
Im building a CRUD system where users can add, delete and edit data from a simple table. I have a modal form that is used to show additional details and also adding new incidents. Currently the modal form loads correctly for editing but has issues when trying to add a new incident.
经过一些调试后,问题似乎出在此行:
After some debuging it seems that the issue comes from this line:
self.currentIncident(null);
这破坏了我的模态形式,因为我的可观察物返回了null(显然).我希望它会返回如下内容:
This breaks my modal form because my observable is coming back null (obviously). I was hoping that it would return something like the following:
"ID": "",
"Description": "",
"Incident": ""
我相信这就是我的模态崩溃的原因,因为我的模态与返回值混淆了.有人会知道一种简单的方法来返回空字符串吗?
I believe this is why my modal is crashing since my modal is confused with the return. Would someone know of an easy method to return empty strings?
self.AddNewIncident = function() {
var id = this.ID;
self.showModal(true);
self.currentIncident(null);
};
这是jsfiddle: http://jsfiddle.net/rqwku4kb/12/
Here is jsfiddle: http://jsfiddle.net/rqwku4kb/12/
推荐答案
输入{}
而不是null
,像这样:
self.currentIncident({});
检查小提琴
这篇关于淘汰赛JS-如何为可观察字段返回空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!