Is this possible to integrate jQuery UI components inside Blazor application?

牧云@^-^@ 提交于 2019-12-02 04:50:59

问题


I want to integrate the jQuery UI component within the Blazor client-side application. The Spinner component looks better in jQuery UI. is this possible? how to integrate it?

I expect to integrate this Spinner component into my Blazor client-side application?

https://jqueryui.com/spinner/


回答1:


This is the way to create a wrapper for a JQuery or JS control:

1.- Enclose JS behavior in functions:

<script>
  var spinner = null;
  window.myWrapperKSUIfunctions = {

    initialize: function () {
        spinner = $( "#spinner" ).spinner();
        $( "button" ).button();
    },

    dissableclick: function () {
      if ( spinner.spinner( "option", "disabled" ) ) {
        spinner.spinner( "enable" );
      } else {
        spinner.spinner( "disable" );
      }
    },

    destroyclick: function () {
      if ( spinner.spinner( "instance" ) ) {
        spinner.spinner( "destroy" );
      } else {
        spinner.spinner();
      }
    },

    getvalueclick: function () {
      alert( spinner.spinner( "value" ) );
    },

    setvalueclick: function () {
      spinner.spinner( "value", 5 );
    },    
  };
</script>

Don't forget to include other JS/JQuery libraries.

2.- Initialize control from blazor:

@code {

    protected async override Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            await JsRuntime.InvokeAsync<object>("myWrapperKSUIfunctions.initialize");
        }
    }

3.- Call JS function from blazor:

  <button id="disable" 
          @onclick="@( ()=>JustCall("dissableclick") )" >
     Toggle disable/enable
  </button>
@code {

    ...
    protected async Task JustCall(string f)
    {
        wait JsRuntime.InvokeAsync<object>($"myWrapperKSUIfunctions.{f}"); 
    }

Check it out at blazorfiddle.

Also, take a look to MatBlazor controls.



来源:https://stackoverflow.com/questions/58450009/is-this-possible-to-integrate-jquery-ui-components-inside-blazor-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!