knockout.js

knockout.js partial mapping from json

﹥>﹥吖頭↗ 提交于 2020-01-06 08:27:12
问题 On the knockout.js site's documentation they say that when you get data back from the server you can do this: // Every time data is received from the server: ko.mapping.fromJS(data, viewModel); I'd like to partially map the data back into my object model. Is that possible? I have a viewModel.jobs[i].JobType child object, so I'd like to do something like this: ko.mapping.fromJS(data.jobType, viewModel.jobs[i].JobType); ... meaning I'd like to just map in the jobType from the result from the

What am I doing wrong here returning viewmodel?

冷暖自知 提交于 2020-01-06 08:26:09
问题 I am trying to convert this to durandal/hottowel. viewModel: define(['plugins/router', 'knockout', 'services/logger', 'durandal/app', 'mapping', 'services/routeconfig', 'services/dataBindingHandlers', 'services/appsecurity'], function (router, ko, logger, app, mapping, routeconfig, dataBindingHandlers, appsecurity) { function activate() { logger.log(viewModel.title + "'s View Activated", null, viewModel.title, true); return true; } var viewModel = { activate: active, title: 'Overview', query:

Why is this event being handled twice in knockout?

非 Y 不嫁゛ 提交于 2020-01-06 08:15:30
问题 For some reason the below code makes the links' click event fire twice. I'm relatively new to knockout and I think I might have done my custom binding wrong. Can anyone tell me what I've done wrong? (Btw, the reason I didn't post a fiddle is that I can't include the mapping plugin from github on jsfiddle.) JS: ko.bindingHandlers.activityContent = { init: function(element, valueAccessor, allBindings, viewModel, bindingContext) { // This will be called when the binding is first applied to an

Uncaught SyntaxError: Unexpected token < in solr

流过昼夜 提交于 2020-01-06 07:58:07
问题 I am trying to add a new document in the solr server. My Code $.ajax({ type: "POST", url: "http://192.168.10.113:8080/solr/update/json?commit=true", data: { "add": { "doc": { 'id': '19990' } } }, dataType: 'jsonp', crossDomain: true, jsonp: 'json.wrf', success: function (data) { alert(data); }, failure: function (errMsg) { alert(errMsg); } }); My Solr server is hosted in different domain so i wrote dataType: 'jsonp', crossDomain: true, jsonp: 'json.wrf', to over come from cross domain problem

KnockoutJs: my computed function is not dynamically changing the elements in my view

戏子无情 提交于 2020-01-06 06:45:14
问题 I have an application that retrieves a list of users in my database in a paginated way. The first page shows the first 6 users, and when i click the next page in my pagination i get the next 6 users. I get the first list of 6 users, but the problem is after retrieving the next 6 and applying the binding, it doesn't change on the View, and i am sure it retrieves the next 6 because i console logged it. this is the code this.get("#/search/query::username", function (context) { var searchKeyWord

KnockoutJS - update observable from another modelview

余生颓废 提交于 2020-01-06 04:53:09
问题 I have an existing ComposePopupView() modelview which contains observable this.attachments = ko.observableArray([]); and a method below ComposePopupView.prototype.addDropboxAttachment = function (oDropboxFile) { var oAttachment = null, iAttachmentSizeLimit = Utils.pInt(Settings.settingsGet('AttachmentLimit')), mSize = oDropboxFile['bytes'] ; oAttachment = new ComposeAttachmentModel( oDropboxFile['link'], oDropboxFile['name'], mSize ); oAttachment.fromMessage = false; oAttachment.cancel = this

How do I stop, abort or cancel ApplyBindings during processing?

你说的曾经没有我的故事 提交于 2020-01-06 03:43:26
问题 I know there is no callback mechanism i can hook into... but can I cancel or abort an applyBindings call? This is important if for example I have asynchronous calls happening to collect component templates etc. 回答1: No. There is no feature in KO to abort or cancel an in-progress applyBindings call. 来源: https://stackoverflow.com/questions/38117968/how-do-i-stop-abort-or-cancel-applybindings-during-processing

see all extenders and custom bindings for observable

淺唱寂寞╮ 提交于 2020-01-06 03:08:37
问题 Is it possible to see all extenders and bindings attached to an observable within Knockout JS? Sample View Model: var viewModel = function(){ var self = this; self.firstName = ko.observable().extend({required: "Please enter a name", logChange: "first name" }); self.lastName = ko.observable().extend({ required:true}); } I am also using several custom bindingHandlers including the Knockout X-Editable Plugin in addition to the KO Validation Plugin Sample Multi-Page View: <!--Screen 1 --> <input

observableArray not updating the UI

不想你离开。 提交于 2020-01-06 02:54:08
问题 I am facing a problem that the UI only updates with correct data after a refresh of the page. I am coming from here observableArray is not defined My JS Code: define( ['knockout'], function (ko) { "use strict"; return { onLoad: function (widget) { widget.getDetails= function (prod) { var abc = prod.DetailsNumbers(); console.log(abc); var someArray= []; someArray= abc.split(','); //console.log(someArray); widget.anotherObservableArray = ko.observableArray(); for (var i = 0; i < someArray

Remove items from Knockout observable array

泪湿孤枕 提交于 2020-01-06 02:48:08
问题 I have the below structure for knockout model. It contains an observable array which in turn contains an object. function ViewModel() { var self = this; self.newItem = ko.observable({ manufacturer: ko.observable(), itemnumber: ko.observable(), itemDescription: ko.observable() }); self.AllItems = ko.observableArray(); self.addItem = function() { self.newItem().manufacturer("test"); self.newItem().itemDescription("data"); self.AllItems.push(self.newItem); }; self.removeItem = function(data) {