knockout-2.0

Knockout Validation async validators: Is this a bug or am I doing something wrong?

那年仲夏 提交于 2019-12-20 09:52:18
问题 I really like how Eric Barnard's knockout validation lib integrates with observables, allows grouping, & offers custom validator pluggability (including on-the-fly validators). There are a couple of places where it could be more UX flexible/friendly, but overall it's reasonably well-documented... except, imo, when it comes to async validators. I wrestled with this for a few hours today before doing a search and landing on this. I think I have the same issues/questions as the original author,

Knockout serialization with ko.toJSON - how to ignore properties that are null

折月煮酒 提交于 2019-12-17 19:33:08
问题 When using: var dataToSave = ko.toJSON(myViewModel); .. is it possible to not serialize values that are null? Serializing my current viewModel creates around 500Kb of JSON most of which is ends up like: "SomeObject": { "Property1": 12345, "Property2": "Sometext", "Property3": null, "Property4": null, "Property5": null, "Property6": null, "Property7": null, "Property8": null, "Property9": false } If I could get the serializer to ignore null values then this could be reduced down to:

Get dynamically inserted HTML to work with knockoutjs

旧街凉风 提交于 2019-12-17 15:38:19
问题 I'm using JQuery DataTables for all my tables because of all the nice built-in features, but it seems the only way to customize the table layout is to set the "sDom" option attribute for the DataTable and use something like $("div.SOMECLASS").html(HTML_HERE) to insert the customized html into the table. (FYI, i'm just trying to customize the header). The problem is I want the inserted html to use knockoutjs binding. Knockout doesn't seem to initialize the binding this way. Is there a way to

utilizing beforeMove/afterMove without a binding?

拈花ヽ惹草 提交于 2019-12-14 04:27:11
问题 I need to detect when items are moved in an observableArray. In my current version (2.1.0) I accomplish this by calling setTimeout on all delete events and waiting to see if an add event follows immediately on its heels: var delayed = []; var key; /* obtained by comparing original observableArray with updated list and iterating all differences */ if( /** record exists in original list but not new list ) { // it was deleted, we don't immediately fire a notification (it may get re-inserted in a

Nested knockout template binding

情到浓时终转凉″ 提交于 2019-12-14 03:35:12
问题 $.ajax({ url: "/survey/surveyQuestions", success: function (questionsData) { $.ajax({ url: "/survey/surveyOptions", success: function (optionsData) { alert(questionsData.length); for (var i = 0; i < questionsData.length; i++) { QuestionsScript.Question = ko.mapping.fromJS(questionsData[i]); ko.applyBindings(QuestionsScript, document.getElementById("innerDiv")); for (var j = 0; j < optionsData.length; j++) { if (optionsData[j].QuestionId = questionsData.QuestionId[i]) { OptionsScript.Option =

Trying to map array from JSON to knockout using mappings

故事扮演 提交于 2019-12-14 03:10:46
问题 Hi I have a JSON array like so [{ "id": "537901a53513fa3374bec718", "images": [], "itemImage": "img/3.jpg", "createdDate": "5/18/2014 6:53:25 PM", "location": [ -2.057802, 52.609711 ] }, { "id": "537901a53513fa3374bec710", "images": [ "img/17.jpg" ], "itemImage": "img/1.jpg", "createdDate": "5/18/2014 6:53:25 PM", "location": [ -2.062251, 52.612397 ] }] I'm trying to use the ko.mapping.fromJSON / JS, but i keep messing up sigh :( var viewModel = {}; in my Ajax success function, viewModel

How to check contain in knockout

六月ゝ 毕业季﹏ 提交于 2019-12-14 01:38:31
问题 I am using knockout and i have one html page where i want to check string with some value. Like i have one string 'A:B:C:D:F:G:H:I', i just want to check this string in html with knockout if. Model var viewModel = function () { var self = this; self.key = ko.observable("A:B:C:D:F:G:H:I"); } View <!-- ko if: key().contains('A') --> <input type="checkbox" checked="checked" value="A"/> <!-- /ko --> <!-- ko if: key().contains('B') --> <input type="checkbox" checked="checked" value="B"/> <!-- /ko

Mapping JSON with knockout fails to populate type defined object properties

北城余情 提交于 2019-12-13 18:34:09
问题 I'm trying to map JSON data using the knockout.mapping plugin, however the heirarcical JSON data fails to populate my object properties correctly, the top level loads fine but not the child 'RootTarget' data? What am I doing wrong? Knockout Javascript var Query = function(json) { this.ID = ko.observable(0); this.Name = ko.observable(); this.RootTargetID = ko.observable(); this.RootTarget = ko.observable(); var mapping = { 'RootTarget': { create: function (args) { return new QueryTarget(args

How to add a row on button click?

落花浮王杯 提交于 2019-12-13 08:15:26
问题 in this fiddle there is an add timing button . There is default row having week day dropdown,from time textfield,to time textfield and hospital drop down.Now when I click on the add timing button I want another row having week day dropdown,from time textfield,to time textfield and hospital dropdown. Can any body please tell me how to do that? This is my knockout code var DocSchedule = function (id, day, fromtime, totime, hospital, hospitalId) { this.id = ko.observable(id); this.day = ko

getting multidimensional array (object) observable in KnockoutJS

扶醉桌前 提交于 2019-12-12 22:15:22
问题 I am building an application with Knockout and find it very useful. Although, I have a problem with getting multidimensional array (object) observable. At the moment I am using following structure: self.form = ko.observableArray(ko.utils.arrayMap(initialData, function(section) { var result = { name : section.name, code : section.code, type : section.type, fields: ko.observableArray(section.fields) }; return result; })); It works well, but I can't get it working if the initialData is more than