knockout.js

Using Knockout with Typeahead.js and Bloodhound.js v0.10

我只是一个虾纸丫 提交于 2019-12-24 12:39:50
问题 I have just converted over to using Bloodhound.js and Typeahead.js with Knockout. I am having a few issues - The Typeahead is not displaying the Name property in the suggestions list I can't figure out how to update the set to query against http://jsfiddle.net/Ea93f/2/ I am 'statically' adding new data right now but it should still show up in the result set, and is not self.addNew = function () { self.someOptions.push(new Option(self.someOptions().length + 1, 'Johnnn')); } I am up for any

Can I make knockout generate bindings from the values in other bindings?

一曲冷凌霜 提交于 2019-12-24 12:34:32
问题 After asking this question and getting an answer I have a modal form which has its contents data bound to a knockout model. this is great and makes it generic and reusable, so long as the form follows the same pattern as template, ie a couple of buttons and a fixed body. What I would like is to make the body dynamic and contain input fields bound to other values on my view model. So I have this: <script id="myModal" type="text/html"> <div class="modal-dialog"> <div class="modal-content"> <div

Storing KnockoutJS modeled data with AmplifyJS

流过昼夜 提交于 2019-12-24 12:34:11
问题 I'm trying to figure out a way to cache my knockoutJS SPA data and I've been experimenting with amplifyJS. Here's one of my GET functions: UserController.prototype.getUsers = function() { var self = this; return $.ajax({ type: 'GET', url: self.Config.api + 'users' }).done(function(data) { self.usersArr(ko.utils.arrayMap(data.users, function(item) { // run each item through model return new self.Model.User(item); })); }).fail(function(data) { // failed }); }; Here's the same function,

Why I lose my session variable?

余生长醉 提交于 2019-12-24 11:53:57
问题 I´m on MVC and using KnockoputJS. I select the value from 2 select. In the first select i choose IDCompany, and the second select i choose IDSubsidiary. I send the model in Json to JsonResult in the controller and I create a variable session and a cookie and save IDCompany in the Session variable and in the cookie with the same name. I do the same with IDSubsidiary. Finally, I return to the ajax function (which call "Save" at first) [HttpPost] public JsonResult Save(ViewModel viewModel) {

Why I lose my session variable?

大憨熊 提交于 2019-12-24 11:48:15
问题 I´m on MVC and using KnockoputJS. I select the value from 2 select. In the first select i choose IDCompany, and the second select i choose IDSubsidiary. I send the model in Json to JsonResult in the controller and I create a variable session and a cookie and save IDCompany in the Session variable and in the cookie with the same name. I do the same with IDSubsidiary. Finally, I return to the ajax function (which call "Save" at first) [HttpPost] public JsonResult Save(ViewModel viewModel) {

Why am I getting a TypeError when querying through breeze during a compose in durandal?

杀马特。学长 韩版系。学妹 提交于 2019-12-24 11:42:42
问题 I'm getting the following error from breeze and q.js when my view and model are being bound by a compose binding statement using durandal. I wrote the view in question in isolation and it works great until I try to do a compose binding with it, it throws this error. I tried moving all the custom properties from my entity constructor function to the initializer and also defering evalution of my computed's but that did nothing to thwart the error. I'm not sure which framework is causing this

Knockout.js ko.applyBindings() hierarchy binding

回眸只為那壹抹淺笑 提交于 2019-12-24 11:36:18
问题 http://jsfiddle.net/3JRVS/1/ In js console I get the error: "Uncaught Error: Unable to parse bindings. Message: ReferenceError: new_book is not defined; Bindings value: value: new_book().name" What am I doing wrong? 回答1: When you call ko.applyBindings with a specific element as the second parameter then it will recursively bind everything under that element. In your case, when you call ko.applyBindings(new AppViewModel(), document.getElementById("content")); it will bind everything under that

Knockout mapping how to add and update

﹥>﹥吖頭↗ 提交于 2019-12-24 11:32:05
问题 I have a js object that looks like the following {Messages: [ {Content: "some content", Id: "203", IsNew: false, Subject: "some Subject"}, .... ]} I would like for 'IsNew' to be observable at the very least. To do this I was using the ko.mapping plugin //Within success of ajax call var vm = ko.mapping.fromJS(data) But I also have a need for a 'SelecetedMessage' observable and a SetSelected function on my vm. But im not sure the best way for these to be a part of my vm. Could someone explain

Hot Towel SPA Durandal Knockout and Dynatree

﹥>﹥吖頭↗ 提交于 2019-12-24 11:27:45
问题 I am trying to get the dynatree control to work in the Hottowel viewmodel, based on this fiddle, http://jsfiddle.net/EZgNs var ViewModel = function() { var self = this; self.initialized = ko.observable(false); self.items = ko.observableArray(); // Use JSFiddle echo to simulate an AJAX service (function() { $.ajax({ url:"/echo/json/", data:data, type:"POST", success:function(data) { // Map the returned JSON to the View Model ko.mapping.fromJS(data, {}, self.items); self.initialized(true); } })

Extending knockout viewmodels with prototype

廉价感情. 提交于 2019-12-24 11:10:50
问题 If a viewmodel is already defined, either manually or automatically with mapping plugin, is there any problem to "extend" (add properties/functions) the viewmodel later in the code by using prototype? I'm aware of the create callback of mapping plugin, I just want to know if there are any implications of using prototype instead? The reason I'm asking is because I'm generating large parts of the viewmodels from server side code, but sometimes need to extend the viewmodel later than at initial