Пожалуйста, что делать правильно. Я пытаюсь использовать ReactiveVar для установки значения заполнителя и продолжаю получать эту ошибку. Он показывает, что ReactivarVar не видит установленную для него функцию.
Это ошибка
Uncaught TypeError: Cannot read property 'set' of undefined
at Object.change #identity (login.js:19)
at blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3775
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3744)
at Blaze.View.<anonymous> (blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3774)
at blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2617
at Object.Blaze._withCurrentView (blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2271)
at Blaze._DOMRange.<anonymous> (blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:2616)
at HTMLSelectElement.<anonymous> (blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:863)
at HTMLDivElement.dispatch (jquery.js?hash=e15504227515793c40a6a3a8ad340399cb657500:5282)
at HTMLDivElement.elemData.handle (jquery.js?hash=e15504227515793c40a6a3a8ad340399cb657500:4934)
Это код
Template.login.onCreated(() => {
this.identify = new ReactiveVar( "" );
});
Template.login.helpers({
identify() {
return Template.instance().identify.get();
}
})
Template.login.events({
'change #identity'(event, template){
event.preventDefault();
if ($(event.target).val() == "one") {
console.info("Enter Phone Number");
template.identify.set( "Enter Phone Number" );
}
if ($(event.target).val() == "two") {
console.info("Enter Phone Number");
template.identify.set( "Enter Age" );
}
if ($(event.target).val() == "one") {
console.info("Enter Phone Number");
template.identify.set( "Enter ID Card Number" );
}
}
});
Это мой файл шаблона
<form class = "startup" id = "startup">
<select name = "identity" style = "width: 310px; height: 40px;" id = "identity" >
<option selected value = "select">Select an option</option>
<option value = "one">One</option>
<option value = "two">Two</option>
<option value = "three">Three</option>
</select>
<input type = "text" name = "identify" id = "identify" required = "true" placeholder= {{identify}} >
<input type = "password" name = "Password" placeholder = "Password" required = "true">
<input type = "submit" value = "Sign Up">
</form>





вы можете использовать эту оболочку ReactiveVar. Она чистая и простая в использовании. Найдите эту полезную ссылку: https://github.com/frozeman/meteor-template-var
Вам нужно установить фактическую ReactiveVar для именованной переменной.
Например
this.identify = new ReactiveVar( "state" );
Теперь вы можете получить к нему доступ таким образом.
Установить переменную (в случае)
temp.identify.state.set("age", 28);
Получить переменную (в помощнике)
Template.identify.state.get("age")
вы должны быть точными в том случае, если темп. второй аргумент метода события