I am trying to send a POST
request when an level Of listview
(In product.xml) is selected and from the response I am trying to build another listview
(In brand.xml).I have succeeded to send the POST
request and get the response.But I have failed to pass the response to view.That is I can not build the view.I think the problem is I can't properly send the data(associated with level text),so I failed.I am getting this error:****Attempt to invoke virtual method 'intjave.lang.Integer.intValue()'** on a null object**. null Here is my code-
product.xml:
<Label text="" horizontalAlignment="left" verticalAlignment="center" tap="brand" />
product.Js:
exports.brand=function (args) { var item =args.object; text=item.text; getBrand(text); }; function getBrand(data) { brand.get(data); frameModule.topmost().navigate("view/brand/brand"); }
Brand_View_Model:
function BrandViewModel() { var viewModel = new Observable({ }); viewModel.get = function (category){ data = category; } viewModel.load = function() { fetch("http://10.0.2.2:8000/user_signup", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ category: data, }) }).then(function(response) { return response.json(); }).then(function(data) { for(var i=0;i<data.length;i++){ viewModel.push({ brand: data[i].brand, }); }; }); } viewModel.empty = function() { while (viewModel.length) { viewModel.pop(); } }; return viewModel; } function handleErrors(response) { if (!response.ok) { console.log(JSON.stringify(response)); throw Error(response.statusText); } return response; } module.exports = BrandViewModel;
** Brand.js:**
var BrandViewModel = require("../../shared/brand_view_model"); var observableModule = require("data/observable"); var page; var data; var brandList = new BrandViewModel([]); var pageData = new observableModule.fromObject({ brandList: brandList }); exports.loaded = function(args) { page = args.object; page.bindingContext = pageData; brandList.empty(); brandList.load(); };
Brand.xml:
<Page loaded="loaded"> <GridLayout> <ListView items="" > <ListView.itemTemplate> <Label text="" horizontalAlignment="left" verticalAlignment="center" tap="brand" /> </ListView.itemTemplate> </ListView> </GridLayout> </Page>
No comments:
Post a Comment