剔除组件窗口小部件模板requirejs html [英] knockout component widget template requirejs html

查看:70
本文介绍了剔除组件窗口小部件模板requirejs html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im实现用于淘汰的窗口小部件示例 http://knockoutjs.com/documentation/component-overview.html

im implementing the widget example for knockout http://knockoutjs.com/documentation/component-overview.html

使用requirejs从外部html加载模板对我不起作用

loading template from external html with requirejs not working for me

ko.components.register('like-or-dislike', {
template: { require: 'text!files/component-like-widget.html' }

});

我将包含模板的html放在外部html中. 用我的相对路径"/views/_leyout"替换"files/" 而且不起作用 我需要一个加载html的text.js文件吗? 有什么例子吗?

i put the html containing the template in external html. replace "files/" with my relative path "/views/_leyout" and it's not working i need a text.js file that loads the html? any example ?

推荐答案

user3144678 的答案是正确的.您应该在项目中包含文本插件.为了弄清楚如何使用它,我做了一个简单的项目:

The answer of user3144678 is correct. You should include text plugin inside your project. Just for clarify how to use it I did some simple project:

项目结构:

project
|-- index.html
|-- app.js
`-- content
    `-- some-content.html

index.html:

index.html:

<html>
    <head>
    </head>
    <body>
        <script data-main="app.js"src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js"></script>
   </body>
</html>

app.js:

requirejs.config({
    paths: {
        "text": "http://cdnjs.cloudflare.com/ajax/libs/require-text/2.0.12/text"
    }
});
requirejs(["text!content/some-text.html"], function (text) {
   alert(text);
});    

some-content.html:

some-content.html:

<div>just some text</div>

结果将带有内部仅一些文本"的提示.

the result will be alert with "just some text" inside.

这篇关于剔除组件窗口小部件模板requirejs html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆