简体   繁体   English

如何进行X可编辑以使用Ajax内容

[英]How do I get x-editable to work with ajax content

I have a question about live loaded ajax content and .editable(); 我对实时加载的ajax内容和.editable()有疑问。

I am loading content via ajax that needs to have the ability to tie into the .editable() functions on the parent page. 我正在通过ajax加载内容,该内容需要能够绑定到父页面上的.editable()函数。 I am not finding much in terms of documentation that addresses this. 在解决此问题的文档方面,我发现不多。 I think I must be blind or sumthin'. 我想我一定是瞎子或总结。

How do I get this .editable to work when trying to access it via ajax live loaded content: 当尝试通过ajax实时加载的内容访问该.editable时,如何使它工作:

 $('#charge_name a').editable({
     // scripts here...
 });

Thanks so much for your help!!! 非常感谢你的帮助!!!

Among the options there is a parameter called selector 在这些选项中,有一个称为selector的参数

More info here http://vitalets.github.io/x-editable/docs.html#editable 此处的更多信息http://vitalets.github.io/x-editable/docs.html#editable

This would delegate editable to the targets even after they've been added to the DOM after load. 即使将目标添加到DOM之后,也可以将可委托的目标委托给目标。

Im not sure if this is the best approach, but for the sake of not being able to find a better solution, this is what I have come up with: 我不确定这是否是最好的方法,但是为了找不到更好的解决方案,我提出了以下建议:

I created a function to contain my editable script such as this: 我创建了一个函数来包含我的可编辑脚本,例如:

 function myEditables(){
       $('#charge_name a').editable({
          // scripts here...
       });
 }

Then when ever I need to activate my editables on the page, whether after an ajax call or a page load I just call the name of the function: myEditables(); 然后,无论何时需要激活页面上的可编辑内容,无论是在ajax调用之后还是在页面加载之后,我都只需调用函数的名称即可:myEditables();

If anyone knows of a better way, please let me know I would be more than grateful. 如果有人知道更好的方法,请告诉我,我将不胜感激。 Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM