Jquery mobile 使用Meteor和jQuery Mobile更改按钮文本/图像
我正在使用Meteor构建一个应用程序,但有点不清楚如何使用jQuery Mobile将所有代码组合在一起 基本上,我在标题中有一个编辑按钮,单击时,我希望内容部分中的内容发生更改,编辑按钮应更改为“保存”。单击“保存”按钮应更新内容并将按钮恢复到原始状态 “编辑”按钮看起来像:Jquery mobile 使用Meteor和jQuery Mobile更改按钮文本/图像,jquery-mobile,meteor,Jquery Mobile,Meteor,我正在使用Meteor构建一个应用程序,但有点不清楚如何使用jQuery Mobile将所有代码组合在一起 基本上,我在标题中有一个编辑按钮,单击时,我希望内容部分中的内容发生更改,编辑按钮应更改为“保存”。单击“保存”按钮应更新内容并将按钮恢复到原始状态 “编辑”按钮看起来像: <a data-icon="plus" data-role="button" class="edit" >edit</a> 其思想是在单击编辑按钮时显示输入字段,在单击保存时显示更新的用户输
<a data-icon="plus" data-role="button" class="edit" >edit</a>
其思想是在单击编辑按钮时显示输入字段,在单击保存时显示更新的用户输入文本。很明显,我还没有到服务器端,所以任何关于如何使用Meteor实现这一点的建议都是额外的(我使用{{{>loginButtons}登录facebook)
NB:我对所有人都很陌生。这个。这是一个相对简单的应用程序,因此在根目录中,我只有一个html文件和一个javascript文件,其中包含if(Meteor.is_client)和if(Meteor.is_server)语句。假设您的按钮位于模板中:
<body>
{{> editButton}}
{{> fields}}
</body>
<template name="editButton">
<a data-icon="plus" data-role="button" class="edit" >edit</a>
</template>
Template.editButton.events({
"click [data-role='button']": function(e) {
if ($(e.target).text() == "edit")
$(e.target).text("save");
else
$(e.target).text("edit");
}
});
这将在单击按钮时切换按钮的文本。那么,如何显示或隐藏相关字段呢?我们可以使用:
现在,您需要聆听编辑的值,并使用它告诉Meteor是否应显示相关字段:
<template name="fields">
{{#if editing}}
<input type="text" name="myField"/>
{{/if}}
</template>
Template.fields.editing = function() {
return Session.get("editing");
}
{{{#如果编辑}
{{/if}
Template.fields.editing=函数(){
返回会话。获取(“编辑”);
}
现在,当您单击该按钮时,Meteor将更新相关会话密钥的值,并且由于会话是被动的,它将重新运行Template.fields.editing功能并重新提交字段模板
要保存用户输入的数据,还可以使用会话。我会让你自己解决这一部分,它与我在这里写的代码非常相似。要持久保存用户信息,请查看和
<template name="fields">
{{#if editing}}
<input type="text" name="myField"/>
{{/if}}
</template>
Template.fields.editing = function() {
return Session.get("editing");
}