gpt4 book ai didi

javascript - Meteor 不加载包内的模板,为什么?

转载 作者:行者123 更新时间:2023-11-28 00:08:26 27 4
gpt4 key购买 nike

我花了很长时间试图弄清楚为什么包内的模板(来自autoform-lightstar.htmlafLightStar)没有加载,而如果我复制并将其粘贴到我的主文件 meteor-sample.html 中,一切正常。

我刚刚发布了这个包 to atmospherejs (github 仓库: https://github.com/geeksys/autoform-lightstar )。

> meteor create meteor-sample
> cd meteor-sample
> meteor add aldeed:simple-schema@1.3.3
> meteor add aldeed:autoform@5.3.0
> meteor add aldeed:collection2
> meteor add geeksys:autoform-lightstar (or git clone it to packages/ for tweaks)
<小时/>

meteor-sample.html:

<head>
<title>meteor-sample</title>
</head>

<body>
<div>
{{#each data}}
{{star}}
{{/each}}
</div>
{{> insertDataForm}}
</body>

<template name="insertDataForm">
{{#autoForm collection="Data" id="insertDataForm" type="insert"}}
<fieldset>
<legend>Add Stuff</legend>
{{> afQuickField name='star'}}
</fieldset>
<button type="submit" class="btn btn-primary">Insert</button>
{{/autoForm}}
</template>
<小时/>

meteor-sample.js:

Data = new Mongo.Collection("data");
Data.attachSchema(new SimpleSchema({
'star': {
type: Number,
autoform: {
type: "lightstar",
label: false
}
}
}));

if (Meteor.isClient) {
Template.body.helpers({
data: function () {
return Data.find();
}
});
}

if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
<小时/>

packages/autoform-lightstar/package.js:

Package.describe({
summary: 'AutoForm input type for light star rating',
version: '0.0.1',
name: 'geeksys:autoform-lightstar',
git: 'https://github.com/geeksys/autoform-lightstar.git',
documentation: null
});

Package.onUse(function(api) {
api.versionsFrom('1.1.0.2');
api.use([
'aldeed:autoform@5.0.0',
'templating@1.0.0'
]);

api.addFiles([
'images/star-off.svg',
'images/star-on.svg',
'autoform-lightstar.css',
'autoform-lightstar.js',
'autoform-lightstar.html'
], 'client');
});
<小时/>

packages/autoform-lightstar/autoform-lightstar.html:

<template name="afLightStar">
<div class="af-lightstar" {{dsk}}>
{{#each this.items}}
<input type="radio" id="{{this._id}}" value={{this.value}} {{atts}}>
<label for="{{this._id}}">{{this.label}}</label>
{{/each}}
</div>
</template>
<小时/>

packages/autoform-lightstar/autoform-lightstar.js:

AutoForm.addInputType("lightstar", {
template: "afLightStar",
valueOut: function () {
return this.find('input[type=radio]:checked').val();
},
contextAdjust: function (context) {
context.items = [];
for(var i = 0; i < 5; i++) {
context.items[4 - i] = {
name: context.name,
label: (i + 1).toString(),
value: i + 1,
_id: context.atts.id + '_' + (i + 1).toString(),
selected: (i + 1 === context.value),
atts: _.omit(context.atts, 'id')
};
}

return context;
}
});

Template.afLightStar.helpers({
atts: function selectedAttsAdjust() {
var atts = _.clone(this.atts);
if (this.selected) {
atts.checked = "";
}
// remove data-schema-key attribute because we put it
// on the entire group
delete atts["data-schema-key"];
return atts;
},
dsk: function dsk() {
return {
"data-schema-key": this.atts["data-schema-key"]
};
}
});
<小时/>

packages/autoform-lightstar/autoform-lightstar.css:

.af-lightstar:not(old){
display : inline-block;
width : 7.5em;
height : 1.5em;
overflow : hidden;
vertical-align : bottom;
}

.af-lightstar:not(old) > input{
margin-right : -100%;
opacity : 0;
}

.af-lightstar:not(old) > label{
display : block;
float : right;
position : relative;
background : url('/packages/geeksys_autoform-lightstar/images/star-off.svg');
background-size : contain;
}

.af-lightstar:not(old) > label:before{
content : '';
display : block;
width : 1.5em;
height : 1.5em;
background : url('/packages/geeksys_autoform-lightstar/images/star-on.svg');
background-size : contain;
opacity : 0;
transition : opacity 0.2s linear;
}

.af-lightstar:not(old) > label:hover:before,
.af-lightstar:not(old) > label:hover ~ label:before,
.af-lightstar:not(:hover) > :checked ~ label:before{
opacity : 1;
}
<小时/>

packages/autoform-lightstar/images/star-off.svg:

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24">
<path fill="#fff" stroke="#ccc" d="M 12,2.5 14.4,9.5 21.5,9.5 15.8,13.75 18.5,21.5 12,16.625 5.5,21.5 8.2,13.75 2.5,9.5 9.6,9.5 z"/>
</svg>
<小时/>

packages/autoform-lightstar/images/star-on.svg:

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24">
<path fill="#ffd700" stroke="#ccac00" d="M 12,2.5 14.4,9.5 21.5,9.5 15.8,13.75 18.5,21.5 12,16.625 5.5,21.5 8.2,13.75 2.5,9.5 9.6,9.5 z"/>
</svg>

感谢任何帮助。

最佳答案

更改顺序:

api.addFiles([
'images/star-off.svg',
'images/star-on.svg',
'autoform-lightstar.css',
'autoform-lightstar.js',
'autoform-lightstar.html'
], 'client');

api.addFiles([
'images/star-off.svg',
'images/star-on.svg',
'autoform-lightstar.css',
'autoform-lightstar.html',
'autoform-lightstar.js'
], 'client');

问题已解决......

没有错误,没有文档,通过纯粹的反复试验来解决,我喜欢这个。

关于javascript - Meteor 不加载包内的模板,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31127197/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com