Knockoutjs native template binding and simple array of strings - binding

I'm trying to understand native knockoutjs template binding, especially foreach binding.
Just wondering how to access current item using native bidning? With jQuery.tmpl it is possible using something like $item / $data. How to do the same using native template binding when data source is the arrays of primitives so each item has no named fields? Here is the JSFiddle with two examples, the first - using native binding where data source is array of custom objects, second one - binding to an array of strings. I'm unable get it working, looks like I'm missing something obvious?
Basically I'm trying to understand native bindings and be able refactor following example using native binding: JSFiddle: Comma separated list of checked items so I would be able keep an observable variable which represnts a comma separated list of checked items.

You can use $data to access the raw value like: http://jsfiddle.net/rniemeyer/M73S8/3/.
Here is the other fiddle updated: http://jsfiddle.net/rniemeyer/EGAH9/8/. Not sure the exact functionality that you want to support in it.

I am not sure if this is already answered from the amazing Niemeyer (thanks for all of your help in the Knockout Community!), but I made a jsFiddle to show storing the actual Person objects Selected in an observable array.
I am not sure if that is what you are trying to do, but maybe someone else is researching this looking on how to do this exact thing: bind the actual objects into an observable array, not just the ids (although, i added that too to remind me).
Example of a Checkbox List Selected Object Binding: http://jsfiddle.net/cjgaudin/Dp7Br/

Related

Get List of values Macro Container Umbraco

I have added a Macro Container into my page. Now in the CMS I selected all the Macro's that I wished to be added to the Macro Container field as shown below
Now I'm fairly new in C# and Umbraco I was thinking of retrieving the value using the below code
foreach (var m in node.GetPropertyValue<IEnumerable<Object>>("macro")) {
var n = m;
}
Now I thought it will display in an Array or List form but somehow I got a string of all the content of the Macro's I added
Any idea on how to retrieve those in a list? I'm thinking of looping through all those item to be displayed in my cshtml file. Really appreciate your help on this one.
Update:
This is the component of the Macro I used
Update V2:
The approach I was using was to specify the actual name of the Macro. Like #Umbraco.RenderMacro("StockistStoreLocatorPartial") but what I want is more dynamic like what if the name of the macro comes from the list
can you share your document type with us? Or what is the data type of this "Macro"?
Besides, I wonder if this would fit what you need.

Does #Html.Editfor use data bind

I want to know if #Html.Editfor use databind. In http://msdn.microsoft.com/en-us/library/system.web.mvc.html.editorextensions.editorfor(v=vs.118).aspx
They say that it use a for each method, but one of my colleague makes me doubt by saying that this is databind.
They have mentioned on their page
Returns an HTML input element for each property in the object that is
represented by the .....
Here they are saying that #Html.EditFor is available for each property of the model. Its not same as its using foreach. This is indeed data binding.

Knockout two-way binding getting lost

I have an observable collection that is populated from a service. The UI is constructred using containerless ko tags. I have input boxes which are being bound correctly, but two-way binding is not updating the VM.
I have a reproduced my problem in http://jsfiddle.net/cooper/EHNct/18/
Where am I going wrong?
Your mistake is in your value binding of your inputs. By using the function call volume() you explicitely unwrap the value contained in your observable so that wat is put in your input become static.
Use the simple volume definition in your data binding and everything will works fine.

MVCContrib grid - sorting a custom column

Just started learning to use the grid so please excuse me for the possibly trivial question.
How can I sort by a column that uses another table property?
For ex.
column.For(cust => cust.LinkedTable.someProperty).Sortable(true); definition results in a "Could not find a property called 'someProperty' on type MyProject.Models.Node" error (obvious - the property is actually MyProject.Models.Node.LinkedTable.someProperty)
One of my ideas was to create a helper:
column.For(cust => Helpers.ViewHelper.GetSomeProperty(cust)).Sortable(true);
This doesn't produce the error, but a column isn't getting sorted anyways.
In another words, is there any way to pass a string value to a column and make it sortable?
Should probably rewrite my sort function (just a OrderBy(...) now), but I don't really know how to start:) Any help would be appreciated!
You can do it like this:
column.For(cust => cust.LinkedTable.someProperty).SortColumnName(somePropertyID)
where somePropertyID is a attribute of table cust.
I would like to recommend you the JQuery grid
Check it out, it's very useful

Binding to multple datasources in Silverlight with String.Format

I am trying to bind a label 2 (or more!) fields in a dataset in Silverlight 4. I get a localized string out of a resource file and do a String.Format on it like so:
<TextBlock Name="lblTotals" Text="{Binding TotalItems, StringFormat='You need \{0\} items and \{1\} products.'}" />
This works fine with 1 item but there's no way of doing multiple binds in SL4 it seems.
I found some blog posts on how to bind a single element to multiple fields but it does not seem to support the String.Format part which is critical.
The last caveat is that it is bound to an ObservableCollection, so when these fields change in the data the UI must update too.
Any suggestions? Thanks!
I found a solution here using a converter and binding to the whole object and passing in the string as a converter param.
Then the totals did not update when the grid values updated (despite being linked to OnPropertyChanged) - this was the solution hack here.

Resources