knockout.js

Filter Array Not in Another Array

老子叫甜甜 提交于 2019-12-18 18:58:10
问题 Need to filter one array based on another array. Is there a util function in knock out ? else i need to go with javascript First : var obj1 = [{ "visible": "true", "id": 1 }, { "visible": "true", "id": 2 }, { "visible": "true", "id": 3 }, { "Name": "Test3", "id": 4 }]; Second : var obj2 = [ 2,3] Now i need to filter obj1 based on obj2 and return items from obj1 that are not in obj2 omittng 2,3 in the above data (Comparison on object 1 Id ) output: [{ "visible": "true", "id": 1 }, { "Name":

Using Knockout.js how do bind a Date property to a HTML5 date picker?

家住魔仙堡 提交于 2019-12-18 18:53:31
问题 (this only works in Chrome at the moment as most browsers don't yet implement date picker for input type="date") In the following example MyDate starts out as a Date object with the current date, but this isn't picked up by the date input (which expects its format to be a string in format YYYY/MM/DD). Once you've picked a date in the picker then MyDate becomes a string in format above. How can you bind this so MyDate stays a javascript Date and is interpreted by the input control correctly?

Posting a collection of subclasses

一个人想着一个人 提交于 2019-12-18 16:49:25
问题 I have a requirement for users to edit a list of quotes for a lead, the quotes can be different types such as: QuoteForProductTypeA QuoteForProductTypeB All quote types share a common base class, such as QuoteBase. I have my quotes displaying fine on the front end, and appear to post back the correct data too. However, on the server it doesn't obviously doesn't know which subclass to use, so just uses the base class. I think i need some kind of custom model binder for WebApi to check for a

Posting a collection of subclasses

落花浮王杯 提交于 2019-12-18 16:49:22
问题 I have a requirement for users to edit a list of quotes for a lead, the quotes can be different types such as: QuoteForProductTypeA QuoteForProductTypeB All quote types share a common base class, such as QuoteBase. I have my quotes displaying fine on the front end, and appear to post back the correct data too. However, on the server it doesn't obviously doesn't know which subclass to use, so just uses the base class. I think i need some kind of custom model binder for WebApi to check for a

How safe is client-side HTML Sanitization?

扶醉桌前 提交于 2019-12-18 15:49:24
问题 I have been looking at Pagedown.js lately for the allure of using mark-down on my pages instead of ugly readonly textareas. I am extremely cautious though as it seems easy enough to dupe the sanitized converter. I have seen some discussion around Angular.js and it's html bindings and also heard something when Knockout.js 3.0 came out that there had been a previous unsafeness to the html binding. It would seem all someone would need to do to disable the sanitizer in Pagedown.js for instance is

KnockoutJS bind event after template render

核能气质少年 提交于 2019-12-18 14:48:32
问题 I've been searching for a while, and I'm pretty confident this is a new question, and not a repeat like the title suggests. :) Basically, I'm trying to find out if there is a subscribe-able event that KnockoutJS creates after a template render when using something like jQuery templates. I'd use the built-in "afterRender" but I found out that it doesn't fire if the observable array is cleared. I built this demo to illustrate that problem: http://jsfiddle.net/farina/YWfV8/1/. Also, I'm aware

How to cancel/revert changes to an observable model (or replace model in array with untouched copy)

给你一囗甜甜゛ 提交于 2019-12-18 14:00:11
问题 I have a viewModel with an observableArray of objects with observable variables. My template shows the data with an edit button that hides the display elements and shows input elements with the values bound. You can start editing the data and then you have the option to cancel. I would like this cancel to revert to the unchanged version of the object. I have tried clone the object by doing something like this: viewModel.tempContact = jQuery.extend({}, contact); or viewModel.tempContact =

knockout validation using breeze utility?

白昼怎懂夜的黑 提交于 2019-12-18 13:38:51
问题 Has anyone written a utility that will convert Breeze metadata (captured from entity framework data attributes) into knockout validation extensions (using knockout.validation)? 回答1: I have made an function that reads the metadata from an entity and adds validation rules. app.domain.indicador = (function () { "use strict"; var constructor = function () {...} var initializer = function indicadorInitializer(entity) { var entityType = entity.entityType; if (entityType) { console.log(entityType);

Determine which element was added or removed with a Knockoutjs ObservableArray

烈酒焚心 提交于 2019-12-18 12:55:11
问题 I need to figure out which element was removed from my Knockout observableArray. Please see my jsFiddle. I can subscribe to the change, but it only returns value, which is the current array after the add or remove. self.selectedDataPointOptions.subscribe(function(value) { // how can I see which one was added or removed? alert(value); }); 回答1: Knockout includes ko.utils.compareArrays which you can use to compare one array to another. Here's a helper function that notifies for each added or

Knockout Filtering on Observable Array

≯℡__Kan透↙ 提交于 2019-12-18 12:45:09
问题 I've started learning Knockout and I'm having some trouble filtering an observable array on a button click and displaying the results. This is my model: function Product(data) { this.id = data.id; this.name = data.name; this.price = data.price; this.description = data.desc; this.image = data.image; this.genre = data.genre; this.show = data.show; this.offer_desc = data.offer_desc; this.offer_id = data.offer_id; } function ProductModel() { var self = this; self.products = ko.observableArray([])