knockout.js

Validation / Remote Validation with knockout.js in vb.net mvc

依然范特西╮ 提交于 2019-12-25 01:14:33
问题 Pretty simple goal, I want to make sure a username entered by a user is unique right after they enter it. I thought I could use Remote Validation, but the page uses knockout.js so the viewmodel is JavaScript. From what I gather I would have to have passed in my model that has the data annotations in VB to use Remote Validation. I can't seem to find examples of this feature that include the html so it's hard to figure out. How can I accomplish something similar with knockout? I've seen another

Set viewModel = $data for Component

╄→尐↘猪︶ㄣ 提交于 2019-12-25 00:36:53
问题 I'm just starting to get my head around Knockout Components. Right now I'm trying to create a "Template Only" Component. The issue I ran into is getting the viewmodel of the component set to the $data of where I'm using the Component. I've modified the example from the Knockout page (http://knockoutjs.com/documentation/component-overview.html) Here's a plunk that shows what I've done: http://plnkr.co/edit/23PVEW9aQ63A9yq2wRJp I'm using the component in a foreach like: <ul data-bind="foreach:

edit functionality is not working in knockout js

寵の児 提交于 2019-12-25 00:27:57
问题 I just created an editable using an example available on net.in this when i am trying to edit the grid then it doesn't show the value it shows the input field blank.can any body help ? in edit i am calling this function self.editFruit = function (fruit) { if (self.editingItem() == null) { // start the transaction fruit.beginEdit(self.editTransaction); // shows the edit fields self.editingItem(fruit); } }; here is fiddle jsfiddle 回答1: At the time the binding is evaluated for the first time the

How can I create a typed collection class in Knockout mapping?

混江龙づ霸主 提交于 2019-12-25 00:09:07
问题 I'm using knockout with the mapping plugin so that I can write code like this: function ContactViewModel() { //other properties... this.emails = ko.observableArray(); } function ContactEmailViewModel() { //other properties... this.address = ko.observable(); } var koContactMap = { 'emails': { create: function (options) { return new ContactEmailViewModel(options.data); } } }; var model = new ContactViewModel(); ko.mapping.fromJS([JSON data from web service], koContactMap, model); In English, I

Iterating through a list of users and pushing to an array in knockout

别说谁变了你拦得住时间么 提交于 2019-12-24 22:50:36
问题 I have this script that returns a list of all users. I would like to have: set the viewModel's totalUsers and page properties based on data returned. Iterate through the list of users and push the last user object into the observableArry push() method adds users to already loaded and shown users Purpose I actually want to get a count of all users because i will be loading 20 users a page and when i reach the bottom of the page i will check if i still have more users to load and then load them

Reevaluate a computed function every x seconds in KnockoutJS

人盡茶涼 提交于 2019-12-24 22:31:55
问题 Can I execute the computed function say every 1000 ms to get a new timespan value every 1000 ms displayed in my UI ? self.timespan = ko.computed(function() { return self.orderTime() + " " + new Date(); }); 回答1: Wrap your new Date() in a timer observable, and update it every 1000 ms using setInterval, for example like this: function myViewModel() { var self = this; self.orderTime = ko.observable(new Date(2013,1,1,12,0,0)); self.timer = ko.observable(new Date()); self.timespan = ko.computed

JavaScript confirmation window always returning false on Safari for iPhone

跟風遠走 提交于 2019-12-24 22:27:30
问题 I'm using Knockout.JS to power a form and I have a button that when pressed displays a confirmation window. Only on Safari for iPhone it always returns false. It works with Chrome on my iPhone, and on my iPad and laptop it works on all browsers(including Safari). There are no errors either. self.submitPayment = function(){ var errors2 = ko.validation.group(secondValidationGroup); if (errors2().length == 0) { if(confirm_reservation() == true){ finalizePayment(); //calls function which displays

Data coming from an ObservableArray are displayed twice in my table

随声附和 提交于 2019-12-24 20:45:48
问题 here is my viewModel: ViewModel var sitesTableModel = [ { nameCol: "nameCol-1", pagesCol: "pagesCol-1", }, { nameCol: "nameCol-2", pagesCol: "pagesCol-2", }]; var pagesTableModel = [ { lastCol: "lastCol-1", editedCol: "editedCol-1", }, { lastCol: "lastCol-2", editedCol: "editedCol-2", }]; var viewModel = { sitesTable: ko.observableArray(sitesTableModel), pagesTable: ko.observableArray(pagesTableModel), }; then I call a webservice in this way: AJAX Call ajaxService = (function () { var

Why does a function in a child view model causes a computed in the parent view model to fire?

家住魔仙堡 提交于 2019-12-24 19:44:23
问题 Pushing the button in the following code does 2 things: It executes a function in a nested view model, and also makes a computed in the parent view model to execute. var MasterViewModel = function () { var self = this; self.nested = new FirstViewModel(); self.func = ko.computed (function() { var items = self.nested.array(); alert("executed"); }); } var FirstViewModel = function () { var self = this; self.array = ko.observableArray([]); self.push = function () { self.array.push(new

Access global variables from Require.js in the Chrome Developer Console

不羁的心 提交于 2019-12-24 18:28:52
问题 I am creating an ASP.NET single-page application, and have a require.js config file that runs on application start, referencing jQuery, Sammy.js, and knockout.js. I have created shims for the three third-party libraries to allow me to access them on a global level: require.config({ paths: { "jquery": "/Scripts/jquery-2.1.4.min", "sammy": "/Scripts/sammy-0.7.5.min", "knockout": "/Scripts/knockout-3.3.0", "text": "/Scripts/text", "appVm": "/Scripts/app/appViewModel" }, shim: { "jquery": {