Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding errors on repeater #1235

Closed
neumatho opened this issue Dec 8, 2021 · 1 comment
Closed

Binding errors on repeater #1235

neumatho opened this issue Dec 8, 2021 · 1 comment

Comments

@neumatho
Copy link

neumatho commented Dec 8, 2021

Hi,

If you have a repeater rendered server side using a property with no bind direction, a Knockout Javascript error occurs. Take this simple example:

            <dot:Repeater DataSource="{value: MyData}" RenderSettings.Mode="Server">
                <ItemTemplate>
                    <span>Hello {{value: _this}}</span><br />
                </ItemTemplate>
            </dot:Repeater>

In the view model, you have this property:

		[Bind(Direction.None)]
		public IEnumerable<string> MyData
		{
			get
			{
				return new string[] { "Thomas", "Billy" };
			}
		}

When running this code, you will see the data, since it is rendered on the server, but if you open up the Developer tools in the browser and look at the console tab, you will see this error:

Uncaught ReferenceError: Unable to process binding "dotvvm-SSR-foreach: function(){return {"data":MyData} }"
Message: MyData is not defined
    at dotvvm-SSR-foreach (eval at createBindingsStringEvaluator (knockout:3293), <anonymous>:3:86)
    at evaluateValueAccessor (knockout:3566)
    at knockout:3743
    at ko.computed.disposeWhenNodeIsRemoved (dotvvm--internal:2943)
    at Function.evaluateImmediate_CallReadThenEndDependencyDetection (knockout:2403)
    at Function.evaluateImmediate_CallReadWithDependencyDetection (knockout:2360)
    at Function.evaluateImmediate (knockout:2325)
    at Object.ko.computed.ko.dependentObservable (knockout:2157)
    at init (dotvvm--internal:2942)
    at knockout:3802

If you remove the bind direction on the property, then it works fine, but the data is also part of the view model JSON sent to the browser. Isn't it possible to render this on the server side without sending the data in the view model? Then it doesn't make sense to render it server side, because the data will be sent twice.

-Thomas

@exyi
Copy link
Member

exyi commented May 25, 2022

Hi! Sorry for the late reply, this currently a fundamental limitation of DotVVM, you always have to send the repeater collections to client. You can however mark all properties inside the object as [Bind(Direction.None)] and then use resource binding on them in the markup.

I'm currently working on removing this limitation in #1392 - In that version you'd be able to use <dot:Repeater DataSource={resource: MyData}> ... </dot:Repeater> to render it server-side only.

@exyi exyi closed this as completed May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants