我使用jQuery UI的自动完成程序与创建它的方式略有不同.
基本上我想保留所有相同的功能,唯一的区别是当出现建议框时,我不会在用户进行选择时隐藏建议框,我也不希望该选择填充输入框.autocomplete附加到.
所以,我一直在阅读jQuery UI文档,看来有一种方法可以禁用Select:和Close:事件,但我发现他们解释它的方式非常混乱,因此,这就是为什么我我在这里寻求帮助.
我的jQuery
$( "#comment" ).autocomplete({
source: "comments.php",
minLength: 4,
// Attempt to remove click/select functionality - may be a better way to do this
select: function( event, ui ) {
return false;
},
// Attempt to add custom Class to the open Suggestion box - may be a better way
open : function (event, ui) {
$(this).addClass("suggestion-box");
},
// Attempt to cancel the Close event, so when someone makes a selection, the box does not close …Run Code Online (Sandbox Code Playgroud) 我是 TypeScript 的新手,目前正在使用 Next.js、Redux、Jest 等设置 React 应用程序。但是,在运行应用程序时,我收到一个类型错误,该错误会停止应用程序。
似乎问题出在我传入的道具上。这个组件被一个 HOC 'withRouter' 组件包裹,从 next 返回相同的组件和路由信息,即 {router: {pathname: /}}
我的组件 (Logo.tsx)
import React, { SFC } from 'react';
import { withRouter, WithRouterProps } from 'next/router';
import LogoStyled from './Logo.styled';
interface LogoProps {
router: { pathname: string };
}
const Logo: SFC<LogoProps & WithRouterProps> = ({ router }) => {
const { pathname } = router;
return pathname === '/' ? (
<LogoStyled>Home</LogoStyled>
) : (
<LogoStyled>Not Home</LogoStyled>
);
};
export default withRouter(Logo);
Run Code Online (Sandbox Code Playgroud)
我的笑话测试 …
我目前正在尝试弄清楚如何在将应用程序包装在 Context 提供程序中(从 useReducer 获取值)然后通过带有 useEffect 挂钩的子组件进行更新时避免创建无限循环。
CodeSandbox 上有一个问题示例。
显然,如果不在这里重新发布所有代码,就很难谈论这个问题,但关键点是:
根:
function App() {
const [state, dispatch] = useReducer(reducer, initialState);
const value = { state, dispatch };
return (
<Context.Provider value={value}>
...
</Context.Provider>
Run Code Online (Sandbox Code Playgroud)
孩子:
export const Page1: FC = () => {
const { dispatch, state } = useContext(Context);
const { isLoading } = state;
useEffect(() => {
dispatch({
type: "loading",
payload: false
});
}, [dispatch]);
return (...)
Run Code Online (Sandbox Code Playgroud)
我可能遗漏了一些明显的东西,但任何指针都可能会帮助遇到同样问题的其他人。
reactjs ×2
autocomplete ×1
jestjs ×1
jquery-ui ×1
next.js ×1
react-hooks ×1
typescript ×1
use-context ×1
use-effect ×1
use-reducer ×1