knockout.js

Serialize nested observable arrays to JSON

最后都变了- 提交于 2020-01-05 07:57:36
问题 In KnockoutJS is there a way to serialize nested structures of observable arrays to JSON? I am using JSON.stringify, but since it doesn't access the arrays as someObservableArray(), it will not be able to serialize the nested arrays: Ex: I have an observable array where each item contains an observable array as a property . Currently I am manually converting it to a standard JS object before calling JSON.stringify, but is there another knockout function that will enable me to convert it to

Creating a autocomplete field with Typeahead in the Durandal Framework

送分小仙女□ 提交于 2020-01-05 07:57:34
问题 I'm trying to achieve a autocomplete input field with typeahead (twitter bootstrap). This autocomplete field should be in a modal but I cant seem to get it working! It also must be observable with knockout because when you select a value other fields should be updated to. So I'm kinda looking to do this in a modal! HTML <div class="messageBox"> <div class="modal-header"> <h2>Adding a repairline</h2> </div> <div class="modal-body" style="width: 35em;"> <form data-bind="submit: ok"> <fieldset>

How to obtain input from multiple textareas and radio buttons on the click of a button using knockout?

时光毁灭记忆、已成空白 提交于 2020-01-05 07:48:05
问题 I have several textareas and radio buttons that are dynamically generated inside a ko: foreach binding. When a user decides they are done typing their input, they will click a button 'OK' which takes all of the input of the textareas and values of the radio buttons they have chosen and it should trigger an ajax call to the server because the input needs to be stored in a database. Each textarea and radiobutton value is stored separately, so they need to be sent to the server as distinguished

Detect if a change occur in observableArray

狂风中的少年 提交于 2020-01-05 07:11:09
问题 Does anyone have idea, if it's possible to detect whenever a change occur inside observableArray while using ko mapping, this mean without having to create the model by hand? self.items = ko.observableArray([]) var data = ko.mapping.fromJS(result) self.items.push(data); I would like to log any changes occurred in any property inside my array of objects. Thanks 回答1: If I'm not mistaken, you should be able to use subscribe on the observable to get that information. See the bottom of this page

Razor form with editable collection using partial with Knockout template integration

你说的曾经没有我的故事 提交于 2020-01-05 07:00:10
问题 So, the title is a little contrived, but this is essentially what I want to accomplish: <ul data-bind="template: { name: 'ItemFormTemplate', foreach: Items }"> @foreach (var item in Model.Items) { Html.RenderPartial("_ItemForm", item); } </ul> <script type="text/html" id="ItemFormTemplate"> @{ Html.RenderPartial("_ItemForm", new Item()); } </script> The idea here is that: I want the form for Item to be a partial and I want to use the same partial for both Razor's foreach and feeding Knockout

Accessing viewModel functions by prototype

≡放荡痞女 提交于 2020-01-05 06:59:38
问题 I am attempting to create a generic Container for my viewModels so common methods can be applied a variety of objects without specific knowledge ot the viewModel. The container and contained object would look like this: var containedViewModel = function() { var self = this; self.id = ko.observable(); ... self.doSomething = function() { alert('here'); }; } var ContainerModel = function(cRoot, cModel, cName) { var self = this; self.rootModel = cRoot; // Root view model self.viewName = cName; //

Knockout mapping for nested json

家住魔仙堡 提交于 2020-01-05 05:57:14
问题 I was trying to create a json schema viewer and editor. I need to show the dynamically generated nested json as nested table and must be able to edit them or add new. for that I was trying to map a nested json to knockout observable and to show them as a nested table JSBin sample But I failed to map it can anyone help me map it correctly and help me arrange the child tables as next 'tr'. I'm not getting any error but the values are not displayed. 回答1: The code is absolutely not clean, but it

KnockoutJS computed observable within an observable

被刻印的时光 ゝ 提交于 2020-01-05 05:03:35
问题 I have a ViewModel containing the following observable: self.obFoo = ko.observable({ foo: ko.observable(""), bar: ko.observable("") }); Now I want to add a new computed observable to obFoo that depends on both foo and bar, something like this: self.obFoo = ko.observable({ foo: ko.observable(""), bar: ko.observable(""), foobar: ko.computed(function(){ return foo() + bar(); }) }); The problem is that foo and bar are not defined within the scope of foobar. I tried adding 'this' or even 'self

How to avoid “The action you have requested is not allowed” error with Knockout postJson function call

核能气质少年 提交于 2020-01-05 04:31:08
问题 CodeIgniter gives an error "The action you have requested is not allowed." when it fails the check for CSRF. As I understand it, this means the POST is missing the hidden token from the form that proves that an attack is not being done. The token is generated automatically with a call to the CI form_open function. In my case, I'm using Knockout to post the contents of a ViewModel for saving, like this: ko.utils.postJson($("form")[0], self.pages); I've found solutions elsewhere that simply

Knockout validation after Mapping

两盒软妹~` 提交于 2020-01-05 04:18:12
问题 I'm new to knockout so please bear with me. I'm trying to using mapping plugin to map the Json data received from server to an existing viewModel instance. I'm able to do this without any issue. But in my viewModel I have used validation plugin so as soon as I map data and bind it to the UI, validation kicks and it immediately displays the error info. Is there way to not to display that error message until submit button is clicked. Or am I doing something wrong? Here is the Jsfiddle link For