knockout.js

Swipe to Reveal is not working

霸气de小男生 提交于 2019-12-18 09:46:19
问题 I have implemented a swipe to reveal Oracle JET component. Below is my Js code this.action = ko.observable("No action taken yet"); this.handleReady = function() { // register swipe to reveal for all new list items $("#listview").find(".item-marker").each(function(index) { var item = $(this); var id = item.prop("id"); var startOffcanvas = item.find(".oj-offcanvas-start").first(); var endOffcanvas = item.find(".oj-offcanvas-end").first(); // setup swipe actions oj.SwipeToRevealUtils

Can Knockout.js bindings apply to container tags AND descendants both?

自作多情 提交于 2019-12-18 09:32:01
问题 Let me setup the question with a simple case. I have an HTML table, the rows of which are controlled by an observableArray. It works great. If the observableArray has zero elements in it however, I want a single row to say so. I tried this markup, which "kind of" works: <tbody data-bind="if: $root.data.contacts().length == 0"> <tr> <td>There are no contacts specified yet.</td> </tr> </tbody> <tbody data-bind="foreach: $root.data.contacts"> SNIP - a tbody with the rows is here when elements >

Knockout JS array empty or can't retrieve values?

让人想犯罪 __ 提交于 2019-12-18 09:29:12
问题 I have a Javascript ajax function that retrieves comments from the server(Note: I'm new to Knockout JS): function Comments() { var self = this; self.commentArray = ko.observableArray(); self.getNewerComments = function(lastCommentId) { pageId = $('body').attr('id'); $.ajax({ type: "GET", dataType: "json", url: "Controller/getNewerComments/" + pageId + "/" + lastCommentId, }) .done(function(data) { self.commentArray = ko.observableArray(data); alert(self.commentArray[0].authorName); }) } }

Knockout observableArray not updating

末鹿安然 提交于 2019-12-18 09:15:34
问题 I have an observableArray that won't update in the HTML even though I can log it to the console and see it change. I wish jsfiddle had a console so I could show that part. In the example I posted I have a list of people then I search across that list and try to add the results to a new observableArray. The search result observableArray never updates in the HTML. Here is my Jsfiddle: http://jsfiddle.net/hMmgV/1/ Here is my code: function AppViewModel() { var self = this; self.people = ko

knockout multiselect selectedOptions contains values instead of objects

梦想的初衷 提交于 2019-12-18 07:01:21
问题 I have a select with the attribute multiple. For each option in the select I want the title attribute set (which shows a tooltip). I also want to retrieve the selected options as an array of objects. I managed to get what I want except for the fact that the selected options doesnt return an array of objects but an array of valueTexts. I can't figure out how I get objects in that array. This is the code I got so far: HTML: <select multiple style="width: 150px;" size=15 data-bind="foreach:

Knockout js -> Bind to editable div text?

萝らか妹 提交于 2019-12-18 05:40:15
问题 How can I bind an observable to an editable div text content? 回答1: You will need to modify the default "text" binding so that it is able to write the content of the edited div back to the observable. A simple custom binding handler for this task can look like this: ko.bindingHandlers.editableText = { init: function(element, valueAccessor) { $(element).on('blur', function() { var observable = valueAccessor(); observable( $(this).text() ); }); }, update: function(element, valueAccessor) { var

Single select options binding with jQuery validation is not working

寵の児 提交于 2019-12-18 04:45:12
问题 I am binding a list of objects to a select using knockout. Object Class can have any number of properties <select id="TheProperty_City" name="TheProperty_City" class="required" data-bind="options: cityList, optionsText: 'Name', value: selectedCity, optionsCaption: '--select the city--'" /> This works perfectly fine and I can use viewModel.selectedCity().Name or viewModel.selectedCity().Value for loading child elements. My issue is with jQuery validation. If I leave the statement as above,

building relative URLs for an MVC app with JavaScript

只愿长相守 提交于 2019-12-18 04:42:21
问题 I'm having trouble getting C# and JavaScript/jQuery to play nice here. I have a knockout view model, plain old javascript object... one of its property/methods fires off an .ajax() call, and the url parameter is built using some of its other property values (javascript variables). This works fine when completely contained in JavaScript, but when deployed as an app to IIS, the relative pathing is hosed. In MVC3 normally I would use something like @Url.Action and let the server side build the

knockoutjs overriding bindinghandlers

末鹿安然 提交于 2019-12-18 04:13:06
问题 Hi I'm trying to set ko up so that on any click handler being called a little bit of custom code is run. Whats the easiest way to add some pre and post code to the 'click' bindings handler? 回答1: You can either create a custom binding that wraps the click binding or save off references to the original init and update functions of the click binding and replace the real one. You could either choose to execute some code in the update function which will be triggered when the model value is

Bind template item to the index of the array in KnockoutJS

跟風遠走 提交于 2019-12-18 03:33:44
问题 I need to name the <div>'s in a KnockoutJS template according to the position that they appear in the list for a Jquery plugin like so: <div id="item1">...</div> <div id="item2">...</div> <div id="item3">...</div> Is there a way to bind to the index of the item in the array using KnockoutJS? It would be a shame if I had to add this data to the select on the database using ROWINDEX. 回答1: update: KO now supports a $index context variable that you can use within a foreach (or template with