knockout.js

Refreshing a selected observable when parent is updated

一曲冷凌霜 提交于 2020-01-05 09:21:09
问题 I asked this question previously, but it didn't get much response. It was obvious that I wasn't very clear what I was trying to achieve, so I'll try again. Here's the jsFiddle to play around with I'm working on an app that will (at an interval) call a web method, which will read a database and build up a JSON string to return which is used to construct my view model. When my view model changes I need to mutate all selected observables with the new data. Take this as an example underlying

Refreshing a selected observable when parent is updated

坚强是说给别人听的谎言 提交于 2020-01-05 09:21:06
问题 I asked this question previously, but it didn't get much response. It was obvious that I wasn't very clear what I was trying to achieve, so I'll try again. Here's the jsFiddle to play around with I'm working on an app that will (at an interval) call a web method, which will read a database and build up a JSON string to return which is used to construct my view model. When my view model changes I need to mutate all selected observables with the new data. Take this as an example underlying

How to get the elements bound to a model in Knockoutjs

旧街凉风 提交于 2020-01-05 09:12:16
问题 I want to add a product, find the node an let it flash products = observableArray([]); new_product = new Product(); products.push(new_product); $("tr", new_product.elements).flash(); I tried using afterAdd but it flashed each time I added something. I need to flash only with one of my adding function. The other functions which add should not flash the element. NOTE: flash is a custom JQuery function 回答1: Since an observable can be bound to multiple elements, your best bet is to really come at

Knockout with repeat binding: Initially selected value being overwritten

浪尽此生 提交于 2020-01-05 08:52:16
问题 I have a preset value for a select selectedValue which has a value of "ham". I have 3 options "spam", "ham", "cheese". When the viewmodel is applied, the "ham" value is selected , but the selectedValue looses it's value, so "ham" isn't actually selected although it appears to be. What do I need to change to allow for selectValue to retain it's initial value? Here's the jsfiddle Html <select data-bind="value:selectedValue"> <option data-bind="repeat: values" data-repeat-bind="value: $item(),

Amending link text and array value text based on dropdown selection

假装没事ソ 提交于 2020-01-05 08:46:09
问题 http://jsfiddle.net/pyCTN/115/ If you view the above fiddle and click on a Sort Type link, you can choose between 'Score, Count and Average' and the array will be sorted accordingly. However, I need to make two enhancements: Instead of Sort Type , the dropdown link text below should show the selected sort type i.e. 'Score, Count or Average'. <a class="btn dropdown-toggle" data-bind="text: 'Sort Type'" data-toggle="dropdown"></a> Instead of showing 'Score', the table text should show the

Using Jinja2 template under Knockout attr binding

混江龙づ霸主 提交于 2020-01-05 08:22:09
问题 I am making a project using Flask and Knockoutjs. I am using Knockout to show comments and below the commentor's name would also be displayed which is when clicked takes the person to that user profile Here is the code <a data-bind="attr: { href: '{{ url_for('user_profile')}}' + '/' + name() + '/' + uid() + '/' }"><p data-bind="text: name"></p></a> but in the above code there comes a Jinja2 Template error as BuildError: ('user_profile', {}, None) So I changed the above piece of code referred

Display text when button clicked

独自空忆成欢 提交于 2020-01-05 08:13:29
问题 Creating my first ASP.NET MVC Knockout MVC. I've added a model setting 3 dates. The controller assigns 3 dates. Then they are displayed on screen using the view: <p>First Date: @ko.Html.TextBox(m => m.FirstDate)</p> <p>Second Date: @ko.Html.TextBox(m => m.SecondDate)</p> <p>Third Date: @ko.Html.TextBox(m => m.ThirdDate)</p> @ko.Apply(Model) The @ko.Apply(Model) being the main part which displays the 3 dates. I am trying to only show the 3 dates when a button is clicked, so iv put the code

Display text when button clicked

夙愿已清 提交于 2020-01-05 08:13:06
问题 Creating my first ASP.NET MVC Knockout MVC. I've added a model setting 3 dates. The controller assigns 3 dates. Then they are displayed on screen using the view: <p>First Date: @ko.Html.TextBox(m => m.FirstDate)</p> <p>Second Date: @ko.Html.TextBox(m => m.SecondDate)</p> <p>Third Date: @ko.Html.TextBox(m => m.ThirdDate)</p> @ko.Apply(Model) The @ko.Apply(Model) being the main part which displays the 3 dates. I am trying to only show the 3 dates when a button is clicked, so iv put the code

Knockoutjs binding to Property vs Property()

六眼飞鱼酱① 提交于 2020-01-05 08:12:14
问题 I can write a knockoutjs data binding expression in two different ways: 1. <div data-bind="text: FirstName"></div> 2. <div data-bind="text: FistName()"></div> Note the two parens after FirstName in the second example. They both seem to work. Is there a difference? 回答1: There is a difference. They will only work both if FirstName is a ko.observable . If it is a plain value, only the first variant will work. An observable does not hold its value directly. It is a function that provides access

POST data from knockout.js to CakePHP controller

。_饼干妹妹 提交于 2020-01-05 08:00:12
问题 I'm posting data from a knockout.js page to a controller in cakephp and it says the data was successfully posted, however, my controller doesn't seem to be responding and I don't get an alert back...not even a null response. I even checked the network tab in chrome and it shows the correct data being POSTED Here's the data being posted from my knockout viewmodel file var JSON_order = JSON.stringify({"orderInfo":[{"itemNumber":"1","quantity":"1","price":1.00,"productName":"test"}]}); $.post("